Javascript examples for Boolean:prototype
The prototype constructor can add new properties and methods to JavaScript booleans.
Boolean.prototype refers to the Boolean() object itself.
The following code shows how to Make a new method for JavaScript booleans:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> Boolean.prototype.myValue = function() { if (this.valueOf() == true) {/*from ww w .j a v a2 s . com*/ return "yes"; } else { return "no"; } }; function myFunction() { var a = true; document.getElementById("demo").innerHTML = a.myValue(); } </script> </body> </html>