constructor 属性返回对建立此对象的 Date 函数的引用。javascript
object.constructorjava
var a,b; (function(){ function A (arg1,arg2) { this.a = 1; this.b=2; } A.prototype.log = function () { console.log(this.a); } a = new A(); b = new A(); })() a.log(); // 1 b.log(); // 1
经过以上代码咱们能够获得两个对象,a,b,他们同为类A的实例。由于A在闭包里,因此如今咱们是不能直接访问A的,那若是我想给类A增长新方法怎么办?chrome
// a.constructor.prototype 在chrome,firefox中能够经过 a.__proto__ 直接访问 a.constructor.prototype.log2 = function () { console.log(this.b) } a.log2(); // 2 b.log2(); // 2
经过访问constructor就能够了。 或者我想知道a的构造函数有几个参数?编程