Created
March 24, 2016 13:23
-
-
Save AndiSHFR/cf7cb44807b94f5a4a5c to your computer and use it in GitHub Desktop.
Javascript: String.prototype._toBool
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
// We extend the string object with a little helper function | |
// to convert a boolean value from a string to bool. | |
// var flag = "true"._toBool | |
Object.defineProperty(String.prototype, "_toBool", { | |
get : function() { | |
return (/^(true|1)$/i).test(this); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment