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

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

class - Kivy: how to instantiate a dynamic classes in python -