Advertisement
Guest User

Simulating Php static In Javascript

a guest
Sep 23rd, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*simulating php static keyword in javascript ( http://jsbin.com/xataqaqevini/1/edit )*/
  2.  
  3. function User( name ) {
  4.     this.name = name;
  5.     this.__proto__.count++;
  6.     //User.prototype.count++;
  7.     //Object.getPrototypeOf(this).count++; 
  8. }
  9.  
  10. User.prototype.count = 0;
  11.  
  12. var ali = new User('ali');
  13. var abu = new User('abu');
  14. var adi = new User('adi');
  15.  
  16. console.log(User.prototype.count);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement