Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // attempt 1
- var a = {};
- a["foo"] = "bar";
- function get(hash, key) {
- return(hash[key]);
- }
- if (get(a, k)) alert("bingo"); // alerts when k is "constructor"
- // attempt 2
- var a = {};
- a["foo"] = "bar";
- function get(hash, key) {
- if (hash.hasOwnProperty(key)) return(hash[key]);
- }
- if (get(a, "constructor")) alert("bingo"); // looks good now
- // attempt 3
- var a = {};
- a["foo"] = "bar";
- a["hasOwnProperty"] = 0; // oops! hides the built-in method
- function get(hash, key) {
- if (hash.hasOwnProperty(key)) return(hash[key]); // throws fatal error
- }
- if (get(a, "constructor")) alert("bingo");
Add Comment
Please, Sign In to add comment