Javascript构造函数属性的意义是什么?
constructor
constructor
function Foo(age) { this.age = age;}function Bar() { Foo.call(this, 42); this.name = "baz"; }Bar.prototype = Object.create(Foo.prototype); var b = new Bar; alert(b.constructor); // "Foo". That's OK because we inherit `Foo`'s prototype.alert(b.name); // "baz". Shows that Bar() was called as constructor.alert(b.age); // "42", inherited from `Foo`.
b
Bar
Foo
Bar.prototype.constructor = Bar;
Bar
b
慕的地8271018
蓝山帝景
相关分类