3-10编程练习
来源:3-10 编程练习
慕粉1110144175
2019-03-05 15:35:07
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 工厂模式
function createObject(name){
var obj = new Object();
obj.name=name;
obj.action=function(){
alert("前端");
};
return obj;
}
var obj1=createObject('imooc');
//alert(obj1.name);
//obj1.action();
// 原型模式
function test(){
}
test.prototype.name='imooc';
test.prototype.action=function(){
alert("前端");
};
var obj2=new test();
//alert(obj2.name);
//obj2.action();
// 混合模式
function blog(name){
this.name=name;
}
blog.prototype={
action:function(){
alert("前端");
}
}
var obj3=new blog('imooc');
//alert(obj3.name);
//obj3.action();
</script>
</body>
</html>1回答
好帮手慕星星
2019-03-05
你好,代码实现的没有问题。
祝学习愉快!