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.