speechless. At first, I thought that all the great gods knew this style without adding code. as a result, the problem was trampled on, and the hostility in your community was really heavy. I admire and admire it.
learned about this code style while watching js you don"t know, but it seems (? ) this code style is not particularly common, is it because there are any drawbacks in this style
the following is the object association style & the comparison of object-oriented styles
// ""
function Foo() {
this.me = who;
}
Foo.prototype.identify = function() {
return "I am "+ this.me;
}
function Bar(who) {
Foo.call(this, who);
}
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.speak = function() {
alert("hello, "+ this.identify() + ".");
};
var b1 = new Bar("b1");
var b2 = new Bar("b2");
b1.speak();
b2.speak();
//BarFoo,b1b2b1Bar.prototypeFoo.prototype
//
Foo = {
init: function(who) {
this.me = who;
},
identify: function() {
return "i am "+ this.me
}
};
Bar = Object.create(Foo);
Bar.speak = function() {
alert("hello, "+ this.identify() + ".");
}
var b1 = Object.create(Bar);
b1.init("b1")l
var b2 = Object.create(Bar);
b2.init("b2");
b1.speak();
b2.speak();
//[[prototype]]b1BarBarFoo,new