zoukankan      html  css  js  c++  java
  • javascript

    以下代码为变量 car 设置值为 "Fiat" :

    var car = "Fiat";

    对象也是一个变量,但对象可以包含多个值(多个变量)。

    var car = {type:"Fiat", model:500, color:"white"};

    在以上实例中,3 个值 ("Fiat", 500, "white") 赋予变量 car。

    在以上实例中,3 个变量 (type, model, color) 赋予变量 car。

    Note JavaScript 对象是变量的容器

     prototype 属性


    定义和用法

    prototype 属性允许您向对象添加属性和方法

    注意: Prototype 是全局属性,适用于所有的Javascript对象。

    语法

    object.prototype.name=value

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <script>
            function employee(name, jobtitle, born) {
                this.name = name;
                this.jobtitle = jobtitle;
                this.born = born;
            }
            var fred = new employee("Fred Flintstone", "Caveman", 1970);
     
            employee.prototype.salary = null;
     
            fred.salary = 20000;
     
            document.write(fred.salary);
        </script>

     

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    function Person(name) {
        var _this = {};
        _this._name = name;
     
        _this.sayHello = function() {
            alert("P_hello" + _this._name);
        }
        return _this;
    }
     
    function Teacher(name) {
        // body...
        var _this = Person(name);
        var superSay = _this.sayHello;
        _this.sayHello = function(argument) {
            superSay.call(_this);
            alert("T_hello" + _this._name);
        }
        return _this;
    }
     
    var t = Teacher("aaaa");
    //console.log(t);
    t.sayHello();

     


     
  • 相关阅读:
    SharePoint网站迁移问题
    使用.NET框架自带的Json序列化类
    IL:Hello World
    Javascript面向对象
    抽象代数学习记录
    关于集成测试
    用QTP脚本操作腾讯QQ好友买卖功能
    关于白盒测试一些资料
    Developer小记
    架构设计
  • 原文地址:https://www.cnblogs.com/tangge/p/5708128.html
Copyright © 2011-2022 走看看