Here is my code:
<script>
abc = function(){
;
;
}
= {
getData:function(){
var c = function(num){
alert(num);
= num;
}
c('12345');
},
clearData:function(){
();
alert();
}
}
var d = new abc();
();
</script>
In this section:
var c = function(num){
alert(num);
= num;
}
c('12345');
I want to pass the obtained num to the first definition; but this is not possible, I don’t know how to write it? The format cannot be changed now, only c = function(){ things here}
It can be understood as follows: Quote:
function functionName(arg){……};
functionName(argvalue); It is most familiar to everyone to use functions in this form.
"()" (brackets) can turn a sentence wrapped in it into a "noun". Quote:
(function(formal parameter){function body}) wrap an anonymous function in parentheses, making it equivalent to a "noun" for other parts of the code.
So, quote:
(function(formal parameter){function body})(real parameter) is the most common quote above:
The usage of function names (real arguments) is just as easy to understand, it means defining an anonymous function and calling it immediately. Quote:
c = (function(which){return function(num){alert(num); = num}})(this) defines an anonymous function and is called immediately. This function returns an anonymous function, and the returned function is assigned the name c.
Here, this object is passed as an actual parameter to the formal parameter which provides the reference to the abc instance object to the internal anonymous function.
So c becomes a function that can access the abc instance object.
Technical article, I like it
This is also possible
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
Use bind method
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
<script>
abc = function(){
;
;
}
= {
getData:function(){
var c = function(num){
alert(num);
= num;
}
c('12345');
},
clearData:function(){
();
alert();
}
}
var d = new abc();
();
</script>
In this section:
var c = function(num){
alert(num);
= num;
}
c('12345');
I want to pass the obtained num to the first definition; but this is not possible, I don’t know how to write it? The format cannot be changed now, only c = function(){ things here}
It can be understood as follows: Quote:
function functionName(arg){……};
functionName(argvalue); It is most familiar to everyone to use functions in this form.
"()" (brackets) can turn a sentence wrapped in it into a "noun". Quote:
(function(formal parameter){function body}) wrap an anonymous function in parentheses, making it equivalent to a "noun" for other parts of the code.
So, quote:
(function(formal parameter){function body})(real parameter) is the most common quote above:
The usage of function names (real arguments) is just as easy to understand, it means defining an anonymous function and calling it immediately. Quote:
c = (function(which){return function(num){alert(num); = num}})(this) defines an anonymous function and is called immediately. This function returns an anonymous function, and the returned function is assigned the name c.
Here, this object is passed as an actual parameter to the formal parameter which provides the reference to the abc instance object to the internal anonymous function.
So c becomes a function that can access the abc instance object.
Technical article, I like it
This is also possible
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]
Use bind method
[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]