SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: new and ()

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    new and ()

    I understand the difference between:
    Code:
    function foo() { /* more here */};
    
    var x = foo;
    and
    Code:
    function foo() { /* more here */};
    
    var x = foo();
    The former assigns x the function foo and the latter assigns x the result of invoking foo(). But I don't understand how this interacts with new; I've seen "var o = new Object;" and "var o = new Object();"? Is that the same distinction?

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript has a very forgiving syntax. You don't have to write semi-colons to separate statements -- a newline will do. Likewise, you don't have to put the empty parameter list, when using a function as constructor. It doesn't hurt to put it there though, and for sake of readability, it's good to be consistent.

    So new Foo and new Foo() are completely interchangeable.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •