.prototype() mio_ hasOwnProperty()

.prototype() mio_ hasOwnProperty()

作者:LAMP小白  点击:2091  发布日期:2013-01-02 12:28:00  返回列表

Object.prototype


你可以把他理解为所有对象的父级,当你为这个对象添加了一个方法,就等于为所有对象添加了一个方法,因为其他对象都是继承于他的

mio_lt;scriptmio_gt;
    var man = {
        hands: 2,
        legs: 2,
        heads: 1
    };
    var woman = new Array;
    if ( typeof Object.prototype.clone === "undefined" ) {
        Object.prototype.clone = function () {};
        Object.prototype.haha = 'aaa';
    }
    for ( var i in man ) {
        console.log( i, ":", woman[i] );
    }
mio_lt;/scriptmio_gt;

可以判断一个属性或函数是否属于这个对象本身,而不是继承的,值得一提的是hasOwnProperty仍然是在Object.prototype中的一个函数

mio_lt;scriptmio_gt;
    var man = {
        hands: 2,
        legs: 2,
        heads: 1
    };
    var woman = new Array;
    if ( typeof Object.prototype.clone === "undefined" ) {
        Object.prototype.clone = function () {};
        Object.prototype.haha = 'aaa';
    }
    for ( var i in man ) {
        if ( man.hasOwnProperty(i) )
        console.log( i, ":", man[i] );
    }
mio_lt;/scriptmio_gt;

用于判断一个属性或函数是否在另一个属性或方法中

mio_lt;scriptmio_gt;
    var man = {
        hands: 2,
        legs: 2,
        heads: 1
    };
    var woman = new Array;
    if ( typeof Object.prototype.clone === "undefined" ) {
        Object.prototype.clone = function () {};
        Object.prototype.haha = 'aaa';
    }
    for ( var i in man ) {
        if ( Object.prototype.hasOwnProperty.call( man, i ) ) {
            console.log( i, ":", man[i] );
        }
    }
mio_lt;/scriptmio_gt;




上一篇:for循环的艺术 下一篇:快递查询API
0