[removed] what's the difference between a function name & function reference?

前端 未结 5 1235
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 02:41

I\'m reading the Google Maps API and it states that the:

\"callback: The function to call once the script has loaded. If using the Auto-loading feature, this         


        
5条回答
  •  孤街浪徒
    2020-12-07 03:29

    Well, perhaps what that bit of documentation means to say is that the "name" it expects should be a string containing the name of a function, instead of a "bare" function name (which is a reference to a function) or a function instantiation/definition expression.

    edit OK I see what the deal is. This really isn't a Google Maps thing, it's the Google Javascript loader toolkit. The API does indeed want a string, which makes perfect sense since the function you want to call is inside the code that you're loading, and therefore you can't have a reference to it from the calling environment.

    google.load("feeds", "1", {"callback" : "someFunctionName"});
    

    It would make no sense to write:

    google.load("feeds", "1", {"callback" : someFunctionName});
    

    because "someFunctionName" used like that — as a reference to something — could not possibly be a reference to the right function (if it's defined at all).

提交回复
热议问题