下面的代码有什么区别
1)前两个构造函数是否相同,只是范围不同?
2)如果第三个对象实例化为对象,它们是否与前两个对象相同?
感谢您的帮助?
function StaffMember(name){
this.name = name;
this.total = 0;
this.discountPercent = function(){
//do stuff
};
}
StaffMember.prototype.calculateTax = function(){
//work out tax
};
或者
var StaffMember = function(name){
this.name = name;
this.discountPercent = function(){
//do stuff
};
}
StaffMember.prototype.calculateTax = function(){
//work out tax
};
或者
var StaffMember {
name:"",
discountPercent:function(){
//do stuff
},
calculateTax : function(){
//work out tax
}
}