老师请检查,谢谢
来源:3-10 编程练习
慕勒8522502
2019-10-22 05:13:23
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 工厂模式
// function muke(name){
// var obj = new Object();
// obj.name = name;
// obj.action = function(){
// alert("前端");
// };
// return obj;
// }
// var test = muke("imooc");
// test.action();
// 原型模式
// function muke(){
// }
// muke.prototype.name = "imooc";
// muke.prototype.action = function(){
// alert("前端");
// }
// var obj = new muke();
// obj.action();
// 混合模式
function muke(name){
this.name = name;
}
muke.prototype = {
action: function(){
alert("前端");
}
}
var test = new muke("imooc");
test.action();
</script>
</body>
</html>1回答
同学你好!
代码效果实现的是可以的。
如果帮到了你,欢迎采纳,祝学习愉快~