Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created April 30, 2011 19:25
Show Gist options
  • Save robotlolita/949916 to your computer and use it in GitHub Desktop.
Save robotlolita/949916 to your computer and use it in GitHub Desktop.
function Something(overwrite) {
if (overwrite)
this.foo = 'bar' // foo will be `bar' only for this object
}
// On the prototype you define properties that should be shared by everything.
Something.prototype = { bar: function(){ return this.foo }
, foo: 'baz' }
var x = new Something
x.bar() // 'baz'
var y = new Something(true)
y.bar() // 'bar'
y.foo = 'foo'
x.bar() // 'baz'
y.bar() // 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment