使用或不使用括号“实例化”JavaScript“类”之间有什么区别?
function Animal(name) {
this.name = name;
}
Animal.prototype.sayName = function() {
console.log(this.name);
};
function Dog(name) {
Animal.call(this, name);
}
Dog.prototype = new Animal(null);
Dog.prototype.bark = function() {
console.log("Woof!");
};
var d = new Dog
或
var d = new Dog()