Why does the object literal have no name?

Source: Internet
Author: User

I wonder why the literal declaration of an object cannot have the name of an object like a function?

Like the general Declaration object: var myobj = {name: "Xiaoming", Age: "18"}, you must create and then assign a value to the myobj variable.

function declaration when var func = function () {}; Looks like an object, this is the creation of an anonymous function.

A function with a name, he has a keyword function to use: function MyFunc () {}; Here the MyFunc is the name of the functions.

So, if you want to have a name, you need to have a keyword that declares it.

But JS doesn't have an object keyword like function. So, the object name "This thing is shattered ~

You must assign a value to refer to.

Other ways of creating objects are the 6 modes of construction, factory, prototype, etc. in advanced design.

Why does the object literal have no name?

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.