Class.Singleton 0.1

Class.Singleton defines and instantiates a singleton class.



Details

Author
Eneko Alonso
Current version
0.1
GitHub
eneko/Class.Singleton
Downloads
4505
Category
Native
Tags
Report
GitHub Issues

Releases


Dependencies

  • core:1.2.4/Class/core: 1.2.4
  • _self_/_current_: /MooTools.More

How to use

Class.Singleton objects can be defines as any Mootools class, taking advantage of the nice syntax and benefits of Mootools classes.

var MySingleton = new Class.Singleton({
    initialize: function(){
        // code here
    },
    method1: function(){
        // code here
    },
    method2: function(){
        // code here
    }
});

Inheritance

Singletons also work when building complex classes using inheritance, mixins, etc.

var BaseClass = new Class({
    initialize: function() {
        // Initialization code here
        console.log('BaseClass initialized.');
    },
    method1: function() {
        // some code
    }
});

var MySingleton = new Class.Singleton({
    Extends: BaseClass,
    initialize: function() {
        this.parent();
        console.log('MySingleton initialized.');
    },
    method1: function() {
        this.parent();
        // more code
    }
});

Note that singletons created with Class.Singleton are automatically instantiated and initialized.


Discuss

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