Hi all, this is a question for the more experienced users: I was looking at ways to optimize my code and I found…

Hi all, this is a question for the more experienced users: I was looking at ways to optimize my code and I found that I would be handy if I could assign custom fields to item objects, but LL doesn’t allow me to. The I found this: http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript

I implemented this in a small example script:

dummy = LL.getCurrentDesktop().addShortcut(“dummy”,new Intent(),0,0);

myItem = function(){

this.getCenter = function(){

var r=this.getRotation()*Math.PI/180;

var sin=Math.abs(Math.sin(r));

var cos=Math.abs(Math.cos(r));

var w=this.getWidth()*this.getScaleX();

var h=this.getHeight()*this.getScaleY();

return[this.getPositionX()+(w*cos+h*sin)*0.5,this.getPositionY()+(h*cos+w*sin)*0.5];

};

};

myItem.prototype = dummy;

myDummy = new myItem();

alert(myDummy.getCenter()[0])

alert(myDummy.getPositionX()) // BOTH WORK ON SAME OBJECT AND DIDN’T DEFINE A getPositionX() IN myItem 😀

I never seen anyone use this, so I was wondering if there is anything that makes this very inefficient or I actually discovered something pretty cool.

Thanks for reading 🙂

Colin

http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript
]]>

Leave a Reply

Your email address will not be published. Required fields are marked *