【发布时间】:2018-01-28 16:06:21
【问题描述】:
我用两种不同的方式编写了这两种方法,都给了我相同的结果,所以我什么时候可以使用?
第一个例子
var BaseCls = function() {
BaseCls.prototype.name = "John";
};
var JustCls = new BaseCls();
console.log(JustCls.name); // This is giving result John
第二个例子
var BaseCls = function() {};
BaseCls.prototype.name = "John";
var JustCls = new BaseCls();
console.log(JustCls.name); // This is also giving result John
两者都给了我相同的结果,所以我只想知道是否有任何其他标准导致在主函数内部/外部使用原型编写此属性/方法?
感谢考虑
【问题讨论】:
-
第一个“模式”从未被任何人使用
标签: javascript function oop properties prototype