Last active
March 13, 2017 05:57
-
-
Save jsgao0/12d2c9d3c413a33aef4d52b458352370 to your computer and use it in GitHub Desktop.
Object.leftJoin() implements a function to join 2 objects x and y based on the properties of x. However, if the properties of y are not shown in x then skip copy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x = {a:1, b:2 }; | |
var y = {a:5, c:3, d:5}; | |
Object.leftJoin = function(leftObj, rightObj) { | |
var acceptKeyList = Object.keys(leftObj); | |
var returnObj = {}; | |
for(var key of Object.keys(rightObj)) { | |
if(acceptKeyList.indexOf(key) < 0) { | |
Object.defineProperty(rightObj, key, { | |
enumerable: false | |
}); | |
} | |
} | |
return Object.assign(returnObj, leftObj, rightObj); | |
} | |
console.log(Object.leftJoin(x, y)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment