I think you are not totally clear of what Class means.
The main intention of creating a class is just to make objects of it and work readily. Class is just a prototype of an object.
In javascript, I know you can just declare an object just by passing the function to it. It is just because of its flexibilitty that I can assign functions and methods to any variable. Javascript is not truely object oriented. There are lots of things missing with Javascript.
But I know what is the exact meaning of Prototype, and if I go by its meaning, the only thing that defines a type for you is using Prototype approach.
I strongly deny that creating objects like
var x = { a:20, b:30} or
var x = new object();
x["a"] = 20;
x["y"] = 30;
Is anywhere near declaring a class. Only prototype does. If you define a method to the prototype of a variable, it means you can create new object from it.
like
var x = new MyClass();
just declared.
And it is totally different from
var MyClass = function() {
return { a:20, b:30};
}
var x = MyClass();
So if you go to the depth of Javascript ( I am using it for at least 4 years) you can easily derive, that prototyping is the only way you can make objects appear somewhat similar to what we mean by objects.
Thus if I write
DateTime.prototype.myCustomMethod = function(){
};
I am actually inheriting the type DateTime.
So I recommend you to try out all other methods and derive the logic yourself.
I hope you got my point. Still not.... Give valid reason and example , why you think so. Dont give unnecessary links... all those links are created by peoples like us(other than docs of course).
www.abhisheksur.com
Sagarp, if this helps please login to Mark As Answer. | Alert Moderator