标签:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
通过工厂的方式创建person对象
在createperson中创建一个对象
然后为这个对象设置相应的属性和方法
之后返回这个对象
<script>
function createdog(name,age,color){
var o =new Object();
o.name = name;
o.age = age;
o.color = color;
o.say = function(){
//alert(this.name + "," + this.age);
alert("你叫" + name + "年龄" +age + "体色为" +color);
}
return o;
}
var dog_one=createdog("大黄","20","黄色");
dog_one.say();
var dog_one=createdog("大白","20","白色");
dog_one.say();
var dog_one=createdog("大黑","20","黑色");
dog_one.say();
</script>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/996158041chenlu/p/5734214.html