zoukankan      html  css  js  c++  java
  • 面向对象2

    <script type="text/javascript">
    //			var person1 = new Object();
    //			person1.name = "syz";
    //			person1.age = "26";
    //			person1.say = function(){
    //				alert("my name is "+this.name);
    //			}
    //			person1.say();
    //			
    //			var person2 = new Object();
    //			person2.name = "wmw";
    //			person2.age = "20";
    //			person2.say = function(){
    //				alert("my name is "+this.name+" my boyfriend is "+person1.name);
    //			}
    //			person2.say();
    
    //			工厂模式
    //			function createObj(name,age){//原料
    //				var obj = new Object();//进行加工
    //				obj.name = name;
    //				obj.age = age;
    //				obj.say = function(){
    //					alert(this.name);
    //				}
    //				return obj;//出厂
    //			}
    //			var person1 = createObj("syz","26");
    //			var person2 = createObj("wmw","20");
    //			person1.say();
    //			person2.say();
    //			
    //			alert(person1.say==person2.say);
    
    //			构造函数
    //			function person(name,age){
    //				this.name = name;
    //				this.age = age;
    //				this.say = function(){
    //					alert(this.name);
    //				}
    //			}
    //			var person1 = new person("syz",26);
    //			var person2 = new person("wmw",20);
    //			person1.say();
    //			person2.say();
    //			alert(person1.say==person2.say);
    
    			//function 是函数构造体
    //			function person(name,age){
    //				this.name = name;
    //				this.age = age;
    //			}
    //			person.prototype.sayName = function(){
    //				alert(this.name);
    //			}
    //			person.prototype.sayAge = function(){
    //				alert(this.age);
    //			}
    //			var person1 = new person("syz",26);
    //			var person2 = new person("wmw",20);
    //			person1.say = function(){
    //				alert(1);
    //			}
    //			person1.sayName();
    //			person2.sayAge();
    //			person1.say();
    //			person2.say();
    //			alert(person1.sayName==person2.sayName);
    		</script>
    

      

  • 相关阅读:
    百度打不开
    欢迎大家来到华网科技
    可扩展消息出席协议:核心 RFC 3920
    谈网站的黏度
    手机游戏沙龙7月11日谈话记录
    基于开源软件做个和GTalk聊天的小命令行程序
    WAP网站推广
    算法的魅力
    JSP技术在WAP开发中的应用
    在J2ME实现UTF8转换为Unicode编码的方法
  • 原文地址:https://www.cnblogs.com/mingjixiaohui/p/5247294.html
Copyright © 2011-2022 走看看