javascript - Why can't I reference an object literal from inside an object literal? -
Not sure if this is possible or if I am doing it wrong I am trying to keep an actual reference to an object I am the one who is one of my properties, which is another object literally, I am getting an error stating that it is undefined:
var MyObject = {init: function () {this.elements.buttons.click (function () {alert ('hit');}); }, Element: {button: $ ('button')}} What am I doing?
UPDATE: Main.JS demand which may possibly cancel the scope -
Function Execution Performance Name (functionName, context / *, args * /) {var args = [] .slice.call (arguments) .splice (2); var namespace = functionName.split ("."); Var func = namespaces.pop (); For (var i = 0; i
If you do that work directly MyObject , this will be undefined. This with MyObject and it should work. It will not work as will be defined DOE : var MyObject = {// init: ...} var init = MyObject.init; in this (); See Entering 3 Function Code : If you want to continue using this , you can use or like it: var MyObject = {// init: ...} var init = MyObject.init; init.call (MyObject);
Comments
Post a Comment