https://github.com/elado/mootools-trackinstances
Track Class Instances With a Class Mutator
https://github.com/elado/mootools-trackinstances
Last synced: about 2 months ago
JSON representation
Track Class Instances With a Class Mutator
- Host: GitHub
- URL: https://github.com/elado/mootools-trackinstances
- Owner: elado
- Created: 2010-09-02T16:35:23.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-09-07T10:57:49.000Z (over 14 years ago)
- Last Synced: 2025-02-01T13:25:38.832Z (4 months ago)
- Language: JavaScript
- Homepage: http://devign.me/mootools-track-class-instances-with-the-trackinstances-mutator/
- Size: 102 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
MooTools TrackInstances Class Mutator
=====================================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 -
* A widget class that its instances need to be repositioned upon a window resize
* Stop all music players at once
* Hide all instances of a popup class at onceHow to use
----------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();
});
});[Full post](http://devign.me/mootools-track-class-instances-with-the-trackinstances-mutator/)
[Elad Ossadon's Blog](http://devign.me/)