I know how to call a method from an object i.e. the following if myObj.objMethod is called it will return string.
myObj = {
objProperty: 'string',
objMethod: function() {
return this.objProperty
}
}
However, I am attempting the following code wars exercise and cannot figure out what needs to be done. It looks like they want the function to be called within itself. To do this i have tried using arguments.callee.call(MyObject.objMethod()) but, as expected this exceeds the max call stack. Has anyone got any idea if this is possible to call a method of an object of a function, from within that function?
Here is (one of) my attempt(s) below:
function myFunction() {
var MyObject = {
objProperty: "string",
objMethod: function() {
return this.objProperty;
}
}
return arguments.callee.call(MyObject.objMethod());
};
Here are the code wars instructions:
Property objMethod should be called by myFunction.
Can you fix the syntax so myFunction will be working again? Please check things like braces, commas, and letter case.
and here is the original code provided:
function myFunction() {
var MyObject = {
objProperty: "string",
objMethod: function() {
return myObject.objProperty;
}
}
return myObject.Objmethod();
};
return MyObject.objMethod();return myObject.Objmethod();... note wrong casing