Not sure what I’m doing wrong here, I just want to be able to have functions of an object reference the object scope
myscipt.js
function MyFoo () {
this.name = 'myname';
}
function MyBar () {
this.myFoo = new MyFoo();
function setMyFoosName( name ) {
this.myFoo.name = name;
}
}
somepage.html
<scipt>
$('document').ready( function() {
$.myBar = new MyBar();
}
...
some action
...
$.myBar.setMyFoosName( 'new name' );
</script>
this throws an exception:
this.myFoo.name = name; this.myFoo is not defined
Lekensteyn and Ken got it half right each.
This is how I would do it: