javascript - 为什么要用 [].shift.call( array )之类的方法实现array.shift()呢
天蓬老师
天蓬老师 2017-04-10 16:54:17
# 下面这几个函数里面为什么用call() 这种方式呢 

function.prototype.bind = function () {
    var self = this,
    context  = [].shift.call(arguments),
    args     = [].slice.call(arguments);
    
    return function () {
        return self.apply( context, [].concat.call(args, [].slice.call(arguments)) )
    } 
}


var objectFactory = function () {
    var obj = new Object,
    Constructor = [].shift.call( arguments );
    ......
}

var hasProp = {}.hasOwnProperty;
var extends = function ( child, parent ) {
    for(var key in parent) {
        if (hasProp.call( parent, key)) {
            ......
        }
    }
    ......
}
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!