Last active
December 18, 2015 04:08
-
-
Save danhper/5722834 to your computer and use it in GitHub Desktop.
JS static method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Foo() {} | |
Foo.myStaticMethod = function() { | |
console.log("what a cool method!"); | |
}; | |
Foo.myStaticMethod(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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