Skip to content

Instantly share code, notes, and snippets.

@sagiavinash
Created April 28, 2015 17:10
Show Gist options
  • Save sagiavinash/67fedcf450c35a195243 to your computer and use it in GitHub Desktop.
Save sagiavinash/67fedcf450c35a195243 to your computer and use it in GitHub Desktop.
Import object by values not references
;(function($){
$.importProp = function($this, $src, subset) {
if(subset){
$.each(subset, function(i, key){
$this[key] = $src[key];
});
} else {
$.each($src, function(key, e){
$this[key] = $src[key];
});
}
};
})(jQuery);
var a = {p:"x"};
var b = {q:"y",r:"z",s:"a"};
$.importProp(a, b,["q","s"]);
console.log(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment