I'm writing a small JavaScript game framework and often use objects' properties, like
this.depth = this.y;
But these this
'es are quite annoying @_@. Is there a way to write just…
depth = y;
…not affecting global object?
My instances are created via two factory functions, and they make a limited list of predefined variables, so all of them have depth
, y
, etc. Functions are applied to instances by .apply()
method, though it all may be changed.
The reason I need to omit this
keyword is that the framework is designed not for me only, but for other people too. I don't need to remove this
in the framework itself, but the this
keyword harvests much time while coding applications based on this library. The only solution I know so far is making 'private' variables, but it makes some inconvenience for people who haven't worked with JavaScript before, and manipulating obj1 from obj2 causes making lots of anonymous functions with .apply
– even more hell. So, as I can see, there is no panacea in JavaScript.
Constructors:
/*...*/
'Copy' : function (type) {
var obj = {
'x':0,
'y':0,
'xprev':0,
'yprev':0,
/*...*/
};
return obj;
},
'make' : function (type,x,y) {
obj = ct.types.Copy(type);
obj.x = obj.xprev = obj.xstart = x;
obj.y = obj.yprev = obj.ystart = y;
/*...*/
ct.stack.push(obj);
}
/*...*/