How to access somevar:'this is Foo' from inside bar.foo() ?
function Foo(){
this.somevar='this is Foo';
}
Foo.prototype={
bar:{
somevar:'this is bar'
,foo:function(){
console.log(this);
}
}
}
var instance = new Foo();
instance.bar.foo();
Here is link to jsfiddle: http://jsfiddle.net/jct8n/3/
Foo.prototype.somevar- or do I misunderstand the question?var foo = new Foo();and thenfoo.somevar = 'newValue', callingfoo()would still print 'this is Foo' instead of 'newValue'.prototypeobjects to be methods. Adding objects which itself contain methods doesn't sound like a good pattern.