Skip to content

Instantly share code, notes, and snippets.

@danhper
Last active December 18, 2015 04:08
Show Gist options
  • Save danhper/5722834 to your computer and use it in GitHub Desktop.
Save danhper/5722834 to your computer and use it in GitHub Desktop.
JS static method
function Foo() {}
Foo.myStaticMethod = function() {
console.log("what a cool method!");
};
Foo.myStaticMethod();
var Foo = (function() {
var myPrivateName;
function InnerFoo(name, nickame) {
myPrivateName = name;
this.myPublicNickname = nickame;
}
InnerFoo.prototype.hey = function() {
console.log("Hi, " + myPrivateName + "!");
};
InnerFoo.hiWorld = function() {
console.log("Hi, world!");
};
return InnerFoo;
})();
Foo.hiWorld();
var myFoo = new Foo("Bob", "Bobby");
console.log(myFoo.myPublicNickname + " is public");
myFoo.hey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment