I read crockford’s page on private members http://javascript.crockford.com/private.html in Javascript and got a question which maybe somewhat related. Why should a developer use Prototype?
For example,
For example, I can do this
var Foo = new Object();
Foo.bar = function() { alert('Its a bar'); };
var x = Foo;
x.bar();
instead of
var Foo = function(){};
Foo.prototype.bar = function(){alert('Its a bar');};
var x = new Foo();
x.bar();
Both of these implementations do the same thing. How is one different from the other? Does this affect inheritance in any way?
When you use the prototype pattern, only one instance of attributes you add to the prototype exist.
The prototype pattern has the disadvantage of not being able to access private members.