Creates an instances array property for a class, to contain all of its instances. The array can be used to alter all instances at once, for example -
Just add TrackInstances:true to your class definition, after the initialize method.
var MyClass=new Class({ initialize:function () { }, TrackInstances:true, recalcPosition:function () { // something that recalculates position or any other task that should be applied on an instance } }); var x=new MyClass(); var y=new MyClass(); MyClass.instances; // [x, y] MyClass.instances.length; // 2 // from another code: window.addEvent("resize",function () { MyClass.instances.each(function (instance) { instance.recalcPosition(); }); });
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus