I have the following object:
var x = {
y: '33',
z: '88',
m: function() {
alert('this is the m element');
}
};
x.newObject = function() {
alert('mm');
function click(myval) {
alert('you have select the click function' + myval);
}
};
x.newObject.click('clickme'); // This is what I have tried; it's not working.
How can I call the click function of newObject?
In the way you are coding it, you can’t access
clickfunction since it’s within another function.If you insist coding it this way, have a call to
newObject(which is a function) returnclickin an object so that it can be accessible. It’s usually called function call “chaining”, where the previous call returns an object that the next call can then use: