We are not under a unified VM (syntax not usable) and I cannot spot a single
benefit using two calls rather than one plus implicit init method.
// right now
function Man(name){
// here Man prototype has been already inherited
// and it is usable from "this"
// a constructor is an implicit init method
// let's define the name
this.name = name;
};
var me = new Man("Andrea");
// boring future coolness
function Man(name){
// no instance here, this is the global object
// so we have to call another method from global Object
// requiring scope resolution (Object) property access (create)
// and finally function call plus property access (Man.prototype)
// one up to tow objects creation plus a return
return Object.create(Man.prototype, {
name:{
value:name
}
});
};
So, size wise speaking, we are simply incrementing without a valid reason
our scripts.
Performance speaking, we are simply incrementing execution time for each
instance creation.
WOW, this ES5 will bring a lot of features, isn't it?
wanna obtain the same behavior? EASY
function Man(name){
if(!(this instanceof Man))
return new Man(name);
this.name = name;
};
var me = Man("Andrea");
Still less code, function duality used if necessary, and total cross browser
compatibility.
Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---