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

StackOverflow https://stackoverflow.com/questions/3436498

Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You can find it here Nokia WRT Plug-in for Visual Studio , a plugin for nokia widget developer.

From nokia forum:

The Nokia WRT Plug-in for Visual Studio provides features that enable 
the creation, editing, testing, and deployment of WRT widgets from within
Visual Studio.

try: http://showroom.auction123.com/auction123/index.html

We don't use new at all... We simply set the result of a function and use that as a class.

For example:

// CLASS DECLARATION
var ClassName = function() {

  var public;
  var private;

  var publicFunction = function() {
    // DO STUFF
  };

  // RETURN  OBJECT
  return {
     public: public,
     publicFunction: publicFunction
  };

};

The final return just tells what's going to be public.

Instantiate it by doing:

var object = ClassName();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top