标签:title set cal ret round return content 资源 utf-8
<!DOCTYPE html> <html lang="en"> <head> <title>工厂方式</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script> function createPerson(name,sex){ //构造函数:创建一个对象 //1.原料 var obj = new Object(); //2.加工 obj.name = name; obj.sex = sex; obj.showName = function(){ alert(‘我的名字叫‘+this.name); } obj.showSex = function(){ alert(‘我是‘+this.sex+‘的‘); } //3.出厂 return obj; } var p1 = createPerson(‘sese‘,‘女‘); var p2 = createPerson(‘JJ‘,‘男‘); p1.showName(); p1.showSex(); p2.showName(); p2.showSex(); </script> </head> <body> </body> </html>
标签:title set cal ret round return content 资源 utf-8
原文地址:http://www.cnblogs.com/sese/p/7414288.html