Created
September 6, 2013 10:28
-
-
Save otiai10/6462128 to your computer and use it in GitHub Desktop.
localStorageの構造を変えたので、きっとKey Errorが出る。mergeが必要になった
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 repair = function(given, template){ | |
for(var i in template){ | |
if(typeof given[i] == 'undefined'){ | |
given[i] = template[i]; | |
} | |
} | |
return given; | |
} | |
var obj01 = { | |
'hoge' : 1, | |
'fuga' : 2, | |
'piyo' : 3 | |
} | |
var obj02 = { | |
'hoge' : 11, | |
'foo' : 21, | |
'bar' : 31 | |
} | |
console.log(repair(obj01, obj02)); | |
// { hoge: 1, fuga: 2, piyo: 3, foo: 21, bar: 31 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
いらんかも