标签:type rip har his doctype html UNC 对象 执行环境
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>02-工厂模式</title>
<script>
/*
// 函数在执行的时候,执行环境的作用域是当前函数的调用者
function testThis (){
console.log(this);
}
// window.testThis();
*/
var p1 = {name:‘小明‘,age:18};
var p2 = {name:‘小芳‘,age:18};
var p3 = {name:‘小亮‘,age:18};
var p4 = {name:‘小莉‘,age:18};
var p5 = {name:‘小花‘,age:18};
var p6 = {name:‘小刚‘,age:18};
function createStudent(name,age,sex,sid){
var obj = {
name:name,
age:age,
sex:sex,
sid:sid,
study:function (){
console.log(this.name + ‘好好学习,天天向上‘);
}
}
return obj;
}
var s1 = createStudent(‘小明‘,18,‘b‘,‘20161001‘);
var s2 = createStudent(‘小芳‘,18,‘g‘,‘20161002‘);
var s3 = createStudent(‘小亮‘,18,‘b‘,‘20161003‘);
var s4 = createStudent(‘小莉‘,18,‘g‘,‘20161004‘);
var s5 = createStudent(‘小刚‘,18,‘b‘,‘20161005‘);
// 工厂模式的弊端,不能清楚的知道对象的具体类型
</script>
</head>
<body>
</body>
</html>
标签:type rip har his doctype html UNC 对象 执行环境
原文地址:https://www.cnblogs.com/7qin/p/10226401.html