Skip to content

Instantly share code, notes, and snippets.

@tj
Created August 3, 2011 15:42
Show Gist options
  • Save tj/1122942 to your computer and use it in GitHub Desktop.
Save tj/1122942 to your computer and use it in GitHub Desktop.
less retarded js prototypes
var User = {
toString: function(){
return '<User ' + this.name + '>'
}
};
var Admin = { __proto__: User, isAdmin: true };
var tj = { __proto__: Admin };
tj.name = 'tj';
console.log(tj.toString());
// => <User tj>
console.log(tj.isAdmin);
// => true
@chjj
Copy link

chjj commented Aug 3, 2011

If ECMA standardized __proto__, I might agree with them on something.

@noonat
Copy link

noonat commented Aug 3, 2011

Kind of like Lua metatables. :)

@tj
Copy link
Author

tj commented Aug 3, 2011

yeah if this was the norm and performant I would be one happy camper. Would be nice if proto was just proto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment