zoukankan      html  css  js  c++  java
  • js常用设计模式

    组合使用构造函数模式和原型模式。其中,构造函数模式用于定义实例属性,而原型模式用于定义方法和共享属性。

    例子:

        <script>
            function Person(name,age,job){
                this.name = name;
                this.age = age;
                this.job = job;
                this.friends = ["jie","fei"];
    
            }
    
    //        Person.prototype = {
    //            constructor : Person,
    //            sayName : function(){
    //                alert(this.name);
    //            }
    //        }
            Person.prototype.sayName = function(){
                alert(this.name);
            }
            var  person1 = new  Person("jie",24,"web");
            var person2 = new Person("fei",24,"teacher");
    
            person1.friends.push("wang");
            alert(person1.friends);
            alert(person2.friends);
            alert(person1.friends == person2.friends);
            alert(person1.sayName == person2.sayName);
        </script>
  • 相关阅读:
    软件工程概论
    软件工程概论
    JAVA
    JAVA
    C#字符补位
    C#绘图双缓冲
    C#中IP地址转换为数值的方法
    C#并行编程-并发集合
    C#委托
    C#事件(event)解析
  • 原文地址:https://www.cnblogs.com/scnuwangjie/p/4918577.html
Copyright © 2011-2022 走看看