daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let a = Object.create(null); // doesn't have a prototype
  2. let b = { }; // has Object.prototype
  3.  
  4. var User = function(name) {
  5.     this.name = name;
  6.     /* jshint proto: true */
  7.     this.__proto__ = b;
  8.     // User.prototype.constructor = User // This constructor creates automatically,
  9.     // but it could be easyly overriden with User.prototype = {}
  10. };
  11.  
  12. // This approach doesn't override default prototype's constructor property
  13. User.prototype.hello = function(who) {
  14.     console.log("Hello, " + who.name);
  15. };
  16.  
  17. var vasya = new User("Вася");   // Has __proto__ = User.prototype
  18. var petya = new User("Петя");
  19. petya.hit = () => "Hit";
  20.  
  21.  
  22. vasya.hello(petya);
  23. console.log(petya.hit());
  24. console.log(Object.getPrototypeOf(petya));
RAW Paste Data
Top