Created
August 7, 2015 21:51
-
-
Save chuck0523/0aca60b725b3be2db09f to your computer and use it in GitHub Desktop.
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 obj = { | |
mon : 0, | |
tue : 1, | |
wed : 2, | |
thu : undefined, | |
time : { | |
morning : "5-11", | |
night : "19-22" | |
} | |
} | |
if (typeof Object.create !== 'function') { | |
Object.create = function (o) { | |
var F = function() {}; | |
F.prototype = o; | |
return new F(); | |
}; | |
} | |
var another_obj = Object.create(obj); | |
// プロトタイプのプロパティを見に行く | |
console.log(another_obj.time.morning); //5-11 | |
// 同名のプロパティを設定 | |
another_obj.time.morning = "6-10"; | |
console.log(another_obj.time.morning); //6-10 | |
// 設定したプロパティを削除 | |
delete another_obj.time.morning; | |
console.log(another_obj.time.morning); // undefined !? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment