Skip to content

Instantly share code, notes, and snippets.

@tj
Created August 3, 2011 15:42
Show Gist options
  • Select an option

  • Save tj/1122942 to your computer and use it in GitHub Desktop.

Select an option

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
@noonat

noonat commented Aug 3, 2011

Copy link
Copy Markdown

Kind of like Lua metatables. :)

@tj

tj commented Aug 3, 2011

Copy link
Copy Markdown
Author

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