I am trying to understand the concepts of core javascript. As we all know, We can call functions which are in global context for some event like this.
Html
<span class="name" onclick="clicked()">Name</span>
JavaScript
function clicked(){
alert("span clicked");
}
But why we cannot call function i.e object method like following:
Html
<span class="name" onclick="nameobject.clicked()">Name</span>
javaScript
var nameobject = {
clicked: function(){
alert("Clicked");
}
}
Is there something I am missing? Can someone help me on this?