views:

190

answers:

3

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?

A: 

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();
Alex V
Well, that's all fine for what it does, but there's no inheritance there, prototypal or otherwise... If you have to create every object from scratch every time, I'm guessing you don't create all that many objects!
Shog9
This is the module pattern, which is intended for singletons. Using it for multiple object instantiation as a serve-all strategy will waste memory as every method, property of the created object will be a new object as well. There's zero inheritance, instanceof operator will always return false, isPrototypeOf method will be useless and any attempt to subclass is futile.
BGerrissen
I don't see how, you can just prototype by adding on to the already created object.
Alex V
+1  A: 

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.

BGerrissen
In fact, whenever I personally use the Object.create shim, I only use it in factory patterns and internally for frameworks I write as a hobby. So the only objects I create when tying API's together are object literals containing intrinsic data, which never need subclassing. As the Gang of four advices, use composition over inheritance.
BGerrissen
A: 

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.
Bang Dao