Method for directly declaring an object in js. js declares an object.

Source: Internet
Author: User

Method for directly declaring an object in js. js declares an object.

Var ctrl = {init: function () {this. a (); this. B () ;}, name: "zs", a: function () {alert ("aa") ;}, B: function () {alert ("bb") ;}}; var str = ctrl. name; console.info (str); // zs ctrl. init (); // pop up aa, bb

How does js declare a written object such as var objectOne = {name: 'ss', sex: 'nv ', o: function (p) {alert (p )}}

New is not required, and can be called directly, such as objectOne. name, objectOne. sex, and objectOne. o.

Js Object Problems

Obj = {a: 0,
B: 1,
C: function () {alert ("hello ")},
} This is a syntax for declaring js anonymous objects. This part is used to generate an object obj. This obj has two attributes, a and B. Their values are 0, 1, and, obj also has a method c, which you can reference. a, obj. b, obj. c ()
For unction c () {if (obj) obj. c ()} is to declare a method. if (obj) is used to determine whether obj has been defined. if so, call obj. c (), that is, an alert ("hello") dialog box is generated.

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.