• js原型


    //构造函数

    function Box(name,age)

      this.name = name;                   //实例属性

      this.age =  age; 

      this.run = function(){               //实例方法

       return this.name+this.age+"运行中"

    }

    //原型     (共享)

      function Box(){}     构造函数函数体内什么都没有 这里如果有 叫做实例属性 实例方法

    Box.prototype.name = "Lee";

    Box.prototype.age = 100;

    Box.prototype.run = function(){

     return this.name+this.age+“运行中”

    }

    var box1 = new Box();

    var box2  = new Box();

    alert(box1.run())

    //如果是实例方法,不同的实例化,他们的方法地址是不一样的,是唯一的

    //如果是原型方法,他们的地址是共享的,大家都是一样的

    alert(box1.run == box2.run);

  • 相关阅读:
    PostgreSQL数据库笔记
    LayUI
    Spring
    Mybatis
    Mybatis生成
    server服务器信息页面添加步骤
    Java数据类型和MySql数据类型对应表
    空字符串
    json解析尖括号<>
    JSON--List集合转换成JSON对象
  • 原文地址:https://www.cnblogs.com/bhan/p/5509074.html
Copyright © 2020-2023  润新知