Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 7, 2015 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/0aca60b725b3be2db09f to your computer and use it in GitHub Desktop.
Save chuck0523/0aca60b725b3be2db09f to your computer and use it in GitHub Desktop.
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