Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find an example of a large JavaScript project using Crockford's method for prototypal inheritance? [closed]

I have read about Crockford's push for using JavaScript in a more obviously prototypal manner (cloning objects to create new ones, never using the "new" keyword). But in the wild, I have never seen anybody use this style for larger projects.

Where can I find examples of a large project that uses this style?

like image 736
Boris Yeltz Avatar asked Aug 08 '10 23:08

Boris Yeltz


People also ask

What is prototypal inheritance in JavaScript example?

When we read a property from object , and it's missing, JavaScript automatically takes it from the prototype. In programming, this is called “prototypal inheritance”.

What prototypal inheritance is and how it works in JavaScript?

The Prototypal Inheritance is a feature in javascript used to add methods and properties in objects. It is a method by which an object can inherit the properties and methods of another object. Traditionally, in order to get and set the [[Prototype]] of an object, we use Object. getPrototypeOf and Object.

What kind of inheritance mechanism is used in JavaScript?

In JavaScript, class inheritance is implemented on top of prototypal inheritance, but that does not mean that it does the same thing: JavaScript's class inheritance uses the prototype chain to wire the child `Constructor. prototype` to the parent `Constructor. prototype` for delegation.

Does JavaScript support inheritance?

In JavaScript, an object can inherit properties of another object. The object from where the properties are inherited is called the prototype. In short, objects can inherit properties from other objects — the prototypes.


1 Answers

Have to offer an anti-awnser ;) though like to see big projects using it as well (if there are any). I love Object.create myself and prefer it, though I've never been able to use it widely in a big project nor feel it should be.

  1. OO Developers are addicted to the 'new' operator, it's a hard habbit to get rid off and easy to understand at a glance. Code written in a classical way is right now easier to hand over to the next dev, which already is a strong arguement against Object.create.

  2. Object.create in ES5 (the next JS version) is immensly more powerful and drastically different from Object.create as a shim in ES3 (current JS version). For this reason it's better to avoid Object.create (as is available right now) as a widely used strategy in big projects as it will work differently when ES5 becomes mainstream than is implementable right now.

  3. Big projects make use of frameworks (when you don't have rogue JS 'ninjas' who insist on writing everything from scratch reinventing the wheel over and over again) and all popular frameworks promote prototypical inheritance the classical way. They might have an Object.create method somehwere in the form of .clone() or something, but it's obscured from the tutorials and documentation in respect to object inheritance and subclassing.

  4. Private properties are impossible with Object.create in ES3. I came across more issues the more I fiddled around with Object.create and boy have I fiddled around with it...

I've played around a lot with Object.create and even written a tiny framework around it called 'Objection' (if yer interrested, you'll find it ;) though refraining from linking to github) and 'JSoo' (discontinued). It's just too zany, unfinished and progressive to become mainstream and maintainable in terms of human resources for big projects. I recommend against it whilst being a supporter.

like image 119
BGerrissen Avatar answered Oct 19 '22 14:10

BGerrissen