请问代码是否正确
<!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>0
收起
正在回答
1回答
你好同学,代码实现正确,继续加油,祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星