Javascript examples for Object:Constructor
Using new key word to create object
<html> <head></head> <body> <p>Counting with a local variable.</p> <button type="button" onclick="myFunction()">Count!</button> <p id="demo"></p> <script> function Add(x) {//from w w w . j av a 2 s.c o m var counter = x; return function () {return counter += 1;} }; var add = new Add(0); function myFunction(){ document.getElementById("demo").innerHTML = add(); } </script> </body> </html>