Jump to content

loader


fire7side
 Share

Recommended Posts

I'm having trouble, perhaps it's with my understanding of javascript, but when I use the .load(functionName) it works.  But how do I add perameters?  If I add parenthesis to the function name, it quits working.  Is it just that you can't add parameters or is it some js convention?  I came across the same thing with requestAnimationFrame().  If I add parameters, I get all sorts of problems.

Link to comment
Share on other sites

I'm having trouble, perhaps it's with my understanding of javascript, but when I use the .load(functionName) it works.  But how do I add perameters?  If I add parenthesis to the function name, it quits working.

If you write functionName() as the argument to load then JavaScript calls the function (immediately upon executing the line) and supplies whatever is returned by functionName() as the argument to load().

Is it just that you can't add parameters or is it some js convention?  I came across the same thing with requestAnimationFrame().  If I add parameters, I get all sorts of problems.

You probably want to use bind() [ https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind ] or create an anonymous function with the arguments and call to your actual function baked in eg.

.load( function() { functionName("foo"); } );
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...