请问代码是否正确

来源:3-10 编程练习

mogu54mogu

2019-07-10 11:53:33

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <script type="text/javascript">
 // 工厂模式
 function createObj1 (){
 this.name = "imooc";
 this.action = function(){
 alert("前端");
 }
 }

 var obj1 = new createObj1();
 console.log(obj1.name);
 obj1.action();

 // 原型模式
 function createObj2(){};
 createObj2.prototype.name = "imooc";
 createObj2.prototype.action = function(){
 alert("前端");
 }

 var obj2 = new createObj2();
 console.log(obj2.name);
 obj2.action();
 // 混合模式
 function createObj3(){
 this.name = "imooc";
 }
 createObj3.prototype.action = function(){
 alert("前端");
 }

 var obj3 = new createObj2();
 console.log(obj3.name);
 obj3.action();
 </script>
</body>
</html>


写回答

1回答

好帮手慕夭夭

2019-07-10

你好同学,代码实现正确,继续加油,祝学习愉快!

0

0 学习 · 14456 问题

查看课程

相似问题