JavaScript equivalent of jQuery's extend method

前端 未结 8 2045
小鲜肉
小鲜肉 2020-11-28 02:57

Background

I have a function that takes a config object as an argument. Within the function, I also have default object. Each of those

8条回答
  •  执笔经年
    2020-11-28 03:18

    The approach of Ivan Kuckir's can also be adapted to create a new object prototype:

    Object.prototype.extend = function(b){
    for(var key in b)
        if(b.hasOwnProperty(key))
            this[key] = b[key];
        return this;
    }
    
    var settings = default.extend(config);
    

提交回复
热议问题