js中的构造函数
js中的構(gòu)造函數(shù)
聲明構(gòu)造函數(shù)function Demo(args) { this.a = args.a;this.b = args.b;}構(gòu)造函數(shù)中的this表示新創(chuàng)建的對(duì)象,構(gòu)造函數(shù)自動(dòng)返回this構(gòu)造函數(shù)的原型對(duì)象,能夠被所有實(shí)例繼承Demo.prototype.fn = function() {console.log(this.a + this.b);}let demo = new Demo({a: "aa", b: "bb"}); demo.fn(); // aabbconsole.log(demo.constructor) // [Function: Demo]console.log(demo instanceof Demo); // true轉(zhuǎn)載于:https://www.cnblogs.com/ye-hcj/p/10350338.html
總結(jié)
- 上一篇: Hystrix断路器(五)
- 下一篇: 2019年1月29日