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

你好,代码实现的没有问题。

祝学习愉快!

0

0 学习 · 4826 问题

查看课程

相似问题

回答 1

7-2编程练习

回答 1

6-8编程练习

回答 1

7-7编程练习

回答 1

5-4编程练习

回答 1