Skip to content

Instantly share code, notes, and snippets.

@tatey
Created October 14, 2013 11:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatey/6974057 to your computer and use it in GitHub Desktop.
Save tatey/6974057 to your computer and use it in GitHub Desktop.
var MyClass = function() {
this.myAttribute = 1;
return this;
};
MyClass.classMethod = function() {
};
MyClass.prototype.instancMethod = function() {
};
// Instantiating a class
var instance = new MyClass();
// Calling an instance method
instance.instanceMethod();
// Calling a class method
MyClass.classMethod();
@tatey
Copy link
Author

tatey commented Oct 14, 2013

(function() {
  var _privateMethod, _privateAttribute;

  var MyClass = function() {
    this.myAttribute = 1;
    _privateAttribute = 2;

    return this;
  };

  MyClass.classMethod = function() {
  };

  MyClass.prototype.getPrivateAttribute = function() {
    return _privateAttribute;
  };

  MyClass.prototype.instancMethod = function() {
    _privateMethod.call(this); // Call the private method
  };

  _privateMethod = function() {
  };
})();

@tatey
Copy link
Author

tatey commented Oct 14, 2013

(function(global) {
  var MyClass = function() {
    return this;
  };

  global.MyClass = MyClass;
})(this);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment