请老师检查一下

来源:3-10 编程练习

粉墨登场

2020-11-02 15:11:23


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 工厂模式
function test1(name) {
var test1_Obj = new Object();
test1_Obj.name = 'namce;
test1_Obj.action = function() {
alert('前端');
}
return test_Obj
}
var factory_Obj = test1('imooc');


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

var proto_Obj = new test2();


// 混合模式
function test3(name) {
this.name = name;
}

test3.prototype.action = function() {
alert('前端');
};

var blend_Object = new test3('imooc');


</script>
</body>
</html>


写回答

1回答

好帮手慕夭夭

2020-11-02

同学你好,代码有报错,如下按F12查看:

http://img.mukewang.com/climg/5f9fb2a409c2818519040268.jpg

报错是说有无效的语法,可以按后面的文件名称跳转到有错误的代码。如下:

http://img.mukewang.com/climg/5f9fb2c80938d75105770132.jpg

检查发现,是因为结束的引号忘记写了,那么找到代码改一下即可。如下:

http://img.mukewang.com/climg/5f9fb30a09f5d6e504630080.jpg

以上是一个查找问题的流程,如果遇到报错,可以按照上面的流程自己尝试排查,提升自己独立解决问题的能力哦。代码中还有一个问题,这里老师就不重复上面的步骤了,参考如下调整:

代码中没有定义test_Obj,改为test1_Obj


http://img.mukewang.com/climg/5f9fb38809287c0204870148.jpg

祝学习愉快~


0

0 学习 · 14456 问题

查看课程