The difference between a function object and an object in JavaScript

Source: Internet
Author: User
function Test (word) {    console.log (word);} Test (' Haha, I am a function '), new Test (' Haha, I am the object ');//The above call mode in a more understandable way test.call ("Haha, I am the function");     Equivalent to test ();//equivalent to new test (); var obj = {};obj._proto_ = Test.prototype; Test.call (obj);

 

The essential difference is that this is different from the two calls. Test(‘...‘);when called, the inside of this is the top-level object window , and the return value is undefined. new Test(‘...‘);when called, it will start with a new object, set the type to test, then use it as Test the This function, and finally return the object.

From SF

The difference between a function object and an object in JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.