Last active
August 13, 2016 17:59
-
-
Save bantya/c49a8cdc8b8c749c2a8e65ea0c01a2ef to your computer and use it in GitHub Desktop.
Extending Array with a Getter
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
var X = function () { | |
var self = this; | |
Object.defineProperty(self, 'abc', {get: function () { return 1; }}); | |
}; | |
// Extending & closing the loop | |
X.prototype = Array.prototype; | |
X.prototype.constructor = X; | |
// Works as you'd expect | |
console.log(new X().abc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment