标签:== 策略模式 策略 不同方法 func str 问题 软件 div
1 面向对象的实例对象 2 function Person(name,age){ 3 if(!Person.instance){ 4 Person.instance={ 5 name : "李四", 6 age : "12", 7 showName : function(){ 8 return this.name; 9 }, 10 showAge : function(){ 11 return this.age; 12 } 13 } 14 } 15 return Person.instance; 16 } 17 var ps2 = new Person(); 18 var ps3 = new Person(); 19 20 alert(ps2==ps3) //true
1 01字面量创建方式:var ps1 = { 2 "name" :"张三"; 3 "age" :15; 4 showName:function(){ 5 return this.name; 6 } 7 showAge:function(){ 8 return this.age; 9 } 10 } 11 02:function Person(name,age){ 12 this.name = name; 13 this.age = age; 14 } 15 Person.prototype.showName =function(){ 16 return this.name; 17 } 18 Person.prototype.showAge =function(){ 19 return this.age; 20 } 21 var ps2 = new Person("张三",46); 22 var ps3 = new Person("张三",56); 23 alert(ps2==ps3) //false
1 alert([]==[]); //false 2 alert([] == ![]) //true 3 alert(typeof []); //object
1 //花店 2 function Flower(type){ 3 this.type=type; 4 } 5 //宝宝 6 var Baobao={ 7 sendFlower:function(target){ //给目标者送花 8 var flower = new Flower("狗尾巴花"); //买花 9 target.receiveFlower(flower); //目标者收到花 10 } 11 } 12 //代理送花 13 var Songzhe={ 14 receiveFlower:function(flower){ 15 Marong.receiveFlower(flower); 16 } 17 } 18 var Marong={ 19 receiveFlower:function(flower){ //收花的人 20 alert("收到一束:"+flower.type+",祝你幸福"); 21 } 22 } 23 24 Baobao.sendFlower(Songzhe);
标签:== 策略模式 策略 不同方法 func str 问题 软件 div
原文地址:http://www.cnblogs.com/Makeprogresstogether/p/8011436.html