在构造函数中声明javascript对象方法与在Prototype中声明
var Dog = function(name) { this.Name = name; this.Bark = function() { alert(this.Name + " bark"); };}
var Dog = function(name) { this.Name = name;}Dog.prototype.Bark = function() { alert(this.Name + " bark");};
var dog = new Dog("Fido");dog.Bark(); //Both approaches show "Fido bark"
浮云间
相关分类