-
-
Save rjharmon/789bfaa8dc5ab91bd515 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
function debugAccess(obj, prop, debugGet){ | |
var origValue = obj[prop]; | |
var newKey = "__debug_access_"+prop; | |
obj[newKey] = origValue; | |
Object.defineProperty(obj, prop, { | |
get: function () { | |
if (this !== obj && this.hasOwnProperty(newKey)) { | |
console.log("Inherited object gets its existing COPY of '", prop, "' in ", newKey); | |
return this[newKey]; | |
} | |
if (this === obj) { | |
console.log("Getter: '", prop, "' directly from myself:", obj) | |
} else { | |
console.log("Getter: '", prop, "' inherited from ", obj) | |
} | |
if ( debugGet ) debugger; | |
return this[newKey]; | |
}, | |
set: function(val) { | |
if (this !== obj ) { | |
if (this.hasOwnProperty(newKey)) { | |
console.log("Inherited object updates own copy of '", prop, "' in ", newKey) | |
return this[newKey] = val; | |
} else { | |
console.log("Inherited object creates own copy of '", prop, "' in ", newKey) | |
} | |
} else { | |
console.log("Updating my own '", prop, "' in ", newKey ); | |
} | |
console.log(" ->", val, " on ", this ) | |
debugger; | |
return this[newKey] = val; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment