Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:44:37+00:00 2026-06-07T01:44:37+00:00

Edit: it’s NOT an assignment of a function declaration to a named variable –

  • 0

Edit: it’s NOT an assignment of a function declaration to a named variable – check the accepted answer. Leaving title as it is because other people might make the same error as me.


While reading Paul Irish’s infinitescroll jquery plugin code, I stumbled again and again over the following pattern:

...
_create : function infscr_create (options, callback) { /* ... */ },
...

What is the benefit of doing this instead of:

...
_create : function (options, callback) { /* ... */ },
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:44:39+00:00Added an answer on June 7, 2026 at 1:44 am

    The benefit of that (which is called a “named function expression”) is that the function has an actual name. In your second version, the property has a name, but the function doesn’t. Giving functions actual names helps your tools help you (call stack listings, breakpoint listings, etc.) More: Anonymouses anonymous

    The disadvantage to it is that it has unexpected results in some broken JavaScript engines, like the one in IE8 and earlier. In IE8 and earlier, Paul Irish’s version creates two separate functions at two completely different times. But it’s not really a problem unless you keep and use references to both of them, and expect them to be the same function (for instance, when hooking up and unhooking event handlers). Given it’s Paul, I’m guessing he’s being sure not to do that.


    Re your question title: Note that it’s not a function declaration, but you can be forgiven for thinking it is, as it looks almost exactly like one. 🙂 It’s a function expression. Function declarations and function expressions happen at completely different times, and have different impacts on the scope in which they’re created.

    Just for completeness:

    // This is a function declaration -- note that it's not a "right-hand
    // value", e.g., we're not using the result of it immediately (via an
    // assignment, a property initializer, calling it, or passing it into
    // a function as an argument -- none of those).
    //
    // Declarations happen upon entry to the scope (not as part of step-by-
    // step code). The function's name is added to the scope in which it's
    // declared. Declarations are illegal inside branches (`if`, `try/catch`,
    // `for`, etc.), but some engines will rewrite them as expressions for
    // you if you do that. Others will not, they'll just always declare the
    // function regardless of whether the code was reached. So don't do that.
    function foo() {
    }
    
    // These are all anonymous function expressions. The function in the
    // expression has no name, although some debuggers are pretty smart
    // about looking at the expression and (where they can) listing a
    // kind of pseudo-name for the function. Others are not that smart,
    // which is why I avoid anonymous functions.
    //
    // Expressions happen when they're reached in step-by-step code.
    var f = function() { };
    var obj = {
        prop: function() { }
    };
    doSomethingCoolWithAFunction(function() { });
    (function() { })(); // Call it immediately
    !function() { }();  // Call it immediately
    ~function() { }();  // Call it immediately, there are a few variants
    
    // These are all *named* function expressions.
    //
    // Since they're expressions, they happen when they're reached in the
    // step-by-step code. The function's name is NOT added to the containing
    // scope (except by engines with bugs).
    //
    // These are the same examples as above, but with a name. No other changes.
    var f = function foo() { };
    var obj = {
        prop: function foo() { }
    };
    doSomethingCoolWithAFunction(function foo() { });
    (function foo() { })(); // Call it immediately
    !function foo() { }();  // Call it immediately
    ~function foo() { }();  // Call it immediately, there are a few variants
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I'd like to get a definitive answer on whether or not it's possible
EDIT: I rephrased the question because I have not explained well. Let's see if
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
Edit : Note that, as Daniel and latkin noted in an answer and a
EDIT Leaving this for posterity, but nearly a year later, to get down voted,
EDIT: solved, I know how but I don't understand why. I changed variables declaration
EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've
EDIT : Summary : Git does not allow dates before 1973/03/03 09:46:40 (epoch+100000000s) given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.