zoukankan      html  css  js  c++  java
  • JavaScript对象学习笔记

    参考文章 http://www.cnblogs.com/sanshi/archive/2009/05/07/1454076.html

    //function User(name) {

    //    this.name = name;
    //}

    //User.prototype.getname = function() {

    //    return this.name;
    //}

    //var user = new User('Zhang San');

    //alert(user.constructor === User) //true

    //alert(user.constructor.prototype === User.prototype)//true

    //alert({}.constructor === Object) //true

    //alert([].constructor === Array) //true

    //alert(''.constructor === String)//true

    //alert(user.constructor.prototype.constructor);//User

    function Person(sex) {

        this.sex = sex;
    }

    function User(name) {

        this.name = name;
    }

    User.prototype = new Person('man');

    var user = new User('Zhang San');

    //alert(user.sex); //'man'

    //alert(user.constructor);//Person

    //alert(User.prototype.constructor); //Person

    //Array.prototype.max = function() {
    //    var maxValue = this[0];

    //    for (var i = 1; i < this.length; i++) {

    //        maxValue = this[i];
    //    }
    //    return maxValue;

    //}

    //alert([2, 33, 25].max());//25

    Array.prototype = {

        max: function() {
            var maxValue = this[0];

            for (var i = 1; i < this.length; i++) {

                maxValue = this[i];
            }
            return maxValue;
        }

    };

    alert([2, 33, 25].max());//因为Array.prototype是只读的


     

  • 相关阅读:
    第12-13周总结
    排球比赛计分规则
    我与计算机
    排球比赛计分规则-三层架构
    怎样成为一个高手 观后感
    最后一周冲刺
    本周psp(观众页面)
    本周psp(观众页面)
    本周工作计量
    本周总结
  • 原文地址:https://www.cnblogs.com/johnwonder/p/1676832.html
Copyright © 2011-2022 走看看