Skip to content

Instantly share code, notes, and snippets.

@fuse
Created May 17, 2011 10:25
Show Gist options
  • Save fuse/976253 to your computer and use it in GitHub Desktop.
Save fuse/976253 to your computer and use it in GitHub Desktop.
function A() {
// private
var _foo = "foo";
function foo() {
return _foo;
};
// public
this._bar = "bar";
this.bar = function() {
return this._bar;
}
// public method returning private attribute
this.baz = function() {
return _foo;
}
}
var a = new A;
a.foo()
=> TypeError: a.foo is not a function
a._foo
=> "undefined"
a.bar()
=> "bar"
a._bar
=> "bar"
a.baz()
=> "foo"
// static method
A.parse = function() { … }
var a = new A
a.parse()
// TypeError: a.parse is not a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment