Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $JSKK.Class.create
- (
- {
- $namespace: 'helper',
- $name: 'InstanceTracker'
- }
- )
- (
- // Static Block
- {
- },
- // Instance Block
- {
- _instances: [],
- _nextID: 1,
- length: 0,
- add: function(instance)
- {
- this._instances.push(instance);
- this.length++;
- instance.set('id', this._nextID++);
- },
- getByID: function(id)
- {
- for(var i in this._instances)
- {
- var instance = this._instances[i];
- if(typeof instance != 'object') continue;
- if(instance.get('id') == id) return instance;
- }
- throw new Error('no instance found with id', id);
- },
- removeByID: function(id)
- {
- for(var i in this._instances)
- {
- var instance = this._instances[i];
- if(typeof instance != 'object') continue;
- if(instance.get('id') == id)
- {
- this._instances.splice(i, 1);
- this.length--;
- return true;
- }
- }
- throw new Error('no instance found with id', id);
- },
- deleteByID: function(id)
- {
- for(var i in this._instances)
- {
- var instance = this._instances[i];
- if(typeof instance != 'object') continue;
- if(instance.get('id') == id)
- {
- delete this._instances[i];
- this.length--;
- return true;
- }
- }
- throw new Error('no instance found with id', id);
- },
- _each: function()
- {
- // todo: magix
- }
- }
- );
Add Comment
Please, Sign In to add comment