hoisting - JavaScript multiple alert promt -


I have read about javascript function hoisitng. But in this case, I did not understand how anonymous functions are being hoisted

  var myObj = {name: 'MyName', dob: 10, office: 'MyOffice', myFun: function () {Warning ("Anonymous Job"); }, ShowItem: function () {warning ("name:" + this.name + "office:" + this.office); }}; Warning (myObj.showItem ());  

If I run the code, two warning message indicates. Displays one name, office and other undefined.

That's because two alerts are being said. The first is in the showItem function in its var; Second

  is a warning warning of (myObj.shwItem ());  

Try:

  myObj.showItem ();  

In this case only the alert will be called from within your defined year.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -