Extend Object javascript

object,tipjs

Extend Object javascript

var obj1 = {'a': 'obj2','b':'2'};
var obj2 = {name: 'obj3'};
function extend() {
    var length = arguments.length;
    var target = arguments[0] || {};
    if (typeof target!="object" && typeof target != "function") {
        target = {};
    }
    if (length == 1) {
        target = this;
        i--;
    }
    for (var i = 1; i < length; i++) { 
        var source = arguments[i]; 
        for (var key in source) { 
            if (Object.prototype.hasOwnProperty.call(source, key)) { 
                target[key] = source[key]; 
            } 
        } 
    }
    return target; 
}
console.log(extend(obj1,obj2)); //'a': 'obj2','b':'2', name: 'obj3'}

Có thể bạn đã miss một số snippets code

Detect when your site is visible to users

Detect when your site is visible to users

encode/decode base64 with JS

Encoding to base64 is done with the btoa command

Promise + gì

promise + gì

JavaScript: async/await with forEach

JavaScript: async/await with forEach()

Object.keys và Object.getOwnPropertyNames

Object.keys và Object.getOwnPropertyNames