Are D1
, D2
(and by extension, d1
, d2
) equivalent? What are the notable differences between them, if any?
Also, how should I go about making the prototypes of D1
and D2
unmodifiable via Base.prototype
? Such that neither gets baz
as shown.
var d1, d2
function Base() {this.foo = 'foo'}
Base.prototype.bar = 'bar'
function D1() { }
D1.prototype = new Base()
function D2() {Base.call(this)}
D2.prototype = Object.create(Base.prototype)
Base.prototype.baz = 'baz'
d1 = new D1()
d2 = new D2()
console.log(d1.foo, d1.bar, d1.baz)
//-> foo bar baz
console.log(d2.foo, d2.bar, d2.baz)
//-> foo bar baz