var myClass = function(name){
this.name = name
}
myClass.prototype.sex = "male"
var myClass = new myClass(‘lee‘)
myClass.sex = "female"
console.log(myClass.name)
console.log(myClass.sex)
b. 输出:
lee
female
var myFactory = function(name){
return {
name:name
}
}
myFactory.prototype.sex = "male"
var myFactory = new myFactory(‘lee‘)
myFactory.sex = "female"
console.log(myFactory.name)
console.log(myFactory.sex)
b. 输出:
lee
female
1、可以传递参数
2、可以通过实例化的对象修改类的属性
3、可以动态地向类中添加属性或方法
原文地址:http://blog.51cto.com/12173069/2088281