请问代码是否正确
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// json格式
var obj1 = {
name: "imooc",
action: function(){
alert("前端");
},
};
console.log(obj1.name);
obj1.action();
// Object方式
var obj2 = new Object();
obj2.name = "imooc";
obj2.action = function fn(){
alert("前端")
};
console.log(obj2.name);
obj2.action();
// 构造函数方式
function createObj(){
this.name = "imooc";
this.action = function fn(){
alert("前端")
};
}
var obj3 = new createObj();
console.log(obj3.name);
obj3.action();
</script>
</body>
</html>0
收起
正在回答
1回答
你好同学,代码实现正确,很棒,祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星