Last active
August 29, 2015 14:08
-
-
Save eduardolundgren/4733f405860b2e2c4deb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script> | |
function createDummyNullable(target) { | |
return new Proxy(target, { | |
get: function(wrap, name) { | |
return wrap[name] === undefined ? null : wrap[name]; | |
} | |
}); | |
} | |
var content = createDummyNullable({ | |
key1: 1, | |
key2: 2 | |
}); | |
content.key3 = 3; | |
console.log(content.key1); // 1 | |
console.log(content.key2); // 2 | |
console.log(content.key3); // 3 | |
console.log(content.doesNotExist); // null | |
console.log(content.toString); // Keep existing | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment