Last active
September 20, 2023 13:37
-
-
Save jgphilpott/a876171a09ce00e450d7f4325542d819 to your computer and use it in GitHub Desktop.
A collection of JavaScript Boolean prototype updates.
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
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty | |
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean | |
# Source: https://gist.github.com/jgphilpott/a876171a09ce00e450d7f4325542d819 | |
Object.defineProperty Boolean.prototype, "true", | |
value: -> | |
this is true | |
configurable: false, | |
enumerable: false, | |
writable: false | |
Object.defineProperty Boolean.prototype, "false", | |
value: -> | |
this is false | |
configurable: false, | |
enumerable: false, | |
writable: false | |
Object.defineProperty Boolean.prototype, "boolean", | |
value: -> | |
Boolean this.true() | |
configurable: false, | |
enumerable: false, | |
writable: false | |
Object.defineProperty Boolean.prototype, "number", | |
value: -> | |
Number this | |
configurable: false, | |
enumerable: false, | |
writable: false | |
Object.defineProperty Boolean.prototype, "string", | |
value: -> | |
String this | |
configurable: false, | |
enumerable: false, | |
writable: false | |
Object.defineProperty Boolean.prototype, "array", | |
value: -> | |
Array this | |
configurable: false, | |
enumerable: false, | |
writable: false | |
Object.defineProperty Boolean.prototype, "object", | |
value: -> | |
Object this | |
configurable: false, | |
enumerable: false, | |
writable: false |
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
// Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty | |
// Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean | |
// Source: https://gist.github.com/jgphilpott/a876171a09ce00e450d7f4325542d819 | |
Object.defineProperty(Boolean.prototype, "true", { | |
value: function() { | |
return this == true; | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
Object.defineProperty(Boolean.prototype, "false", { | |
value: function() { | |
return this == false; | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
Object.defineProperty(Boolean.prototype, "boolean", { | |
value: function() { | |
return Boolean(this.true()); | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
Object.defineProperty(Boolean.prototype, "number", { | |
value: function() { | |
return Number(this); | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
Object.defineProperty(Boolean.prototype, "string", { | |
value: function() { | |
return String(this); | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
Object.defineProperty(Boolean.prototype, "array", { | |
value: function() { | |
return Array(this); | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
Object.defineProperty(Boolean.prototype, "object", { | |
value: function() { | |
return Object(this); | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prototyping
This gist is part of a collection of gists that extend JavaScript data prototypes such as
Boolean
,Number
,String
,Array
andObject
. See below for links to all the gists:Note: A loose rather than strict equality check is necessary for the true/false methods to work.