1

I'm trying to clone the functionality of a class in JS that has private functions, public functions and static public functions. I know patterns that provides public and private methods and vars for my classes, but I don't know how to add static methods to this patterns (Revealing pattern in most cases). Any lead to achieve this?

Thanks!

Edit:

Ok, I Know how to achieve a static method, but If I using a pattern like this, How could I create an static method?

var module = (function() {

return function(selector) {
    var options = {
       selector: selector
    }

    var privateFunction = function() {}
    var publicFunction = function() {}

    return {
       public: publicFunction
    }
}
})();
cbelizon
  • 234
  • 2
  • 13
  • Read Mozilla's Introduction to OO JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript – haim770 Jul 03 '13 at 10:35
  • possible duplicate of [Static variables in JavaScript](http://stackoverflow.com/questions/1535631/static-variables-in-javascript) – James Allardice Jul 03 '13 at 10:38

1 Answers1

0

"Static" methods in JavaScript are usually achieved by simply assigning a function to a property of the constructor function object:

function MyClass() {} // Constructor
MyClass.staticMethod = function () {};
James Allardice
  • 164,175
  • 21
  • 332
  • 312