Collapsed. Have you seen this js writing? Expected details: functioninterfaceInit () {Dialog = (function () {varnow = null; return {add: function (id) {alert (id );}, g crashes. Have you seen this js writing? Hope to get detailed instructions
Function interfaceInit (){
Dialog = (function (){
Var now = null;
Return {
Add: function (id ){
Alert (id );
},
GetNow: function (){
Alert (now );
}
}
})();
}
Is this a function or an object? How can I write such a statement? How can I call it?
What are the advantages of such writing? Not everyone can understand it!
------ Solution --------------------
InterfaceInit should be the interface in object-oriented
All classes or functions that inherit the interfaceInit interface must define the Dialog function.
------ Solution --------------------
The Dialog function contains the add and getNow methods. how can this function be called?
============
JScript code
Var init = new interfaceInit (); init. Dialog. add (); init. Dialog. getNow ();
------ Solution --------------------
Will this change be clear?
You can throw the following code into the page, and the alert will output 2.
JScript code
Script var Dialog ={}; function interfaceInit () {var now = null; Dialog = {add: function (id) {alert (id) ;}, getNow: function () {alert (now) ;}} var interface = new interfaceInit (); (function () {var dialog = diface; Dialog. add (2) ;}) () script
------ Solution --------------------
Js anonymous objects.
------ Solution --------------------
To: xuStanly
Have you tested your own code ?!
To: foolbirdflyfirst
JScript code
Script var Dialog ={}; function interfaceInit () {var now = null; Dialog = {add: function (id) {alert (id) ;}, getNow: function () {alert (now) ;}} var interface = new interfaceInit (); (function () {var dialog = diface; Dialog. add (2) ;}) () script
------ Solution --------------------
To ls:
My intention is to let lz understand
1. (function () {alert (1)}) (); // define an anonymous function and execute it immediately.
2. var a = function () {alert (1) ;}a (); // define a variable as a function and then call and execute
The two call methods are actually the same.
So Dialog = (function (){
Return {a: '1', B: '2'} // return an object
})();
Actually it is equivalent to Dialog = {a: '1', B: '2 '}
It can also be easy to understand.
Var a = function () {return {a: '1', B: '2 '}}
Dialog = ();
Alert (Dialog. a) // will alert 1
------ Solution --------------------
JScript code