This question already has answers here:
What is the scope of variables in JavaScript?
(27 answers)
Javascript call nested function
(11 answers)
Closed 2 months ago.
I have this function inside a function, how i call fullName function?
var person = function(){
function fullName(){}
}
person.fullName(); This doesn't work
Related
This question already has answers here:
How to access the correct `this` inside a callback
(13 answers)
JavaScript setInterval and `this` solution
(9 answers)
How do JavaScript closures work?
(86 answers)
Closed 10 months ago.
I've noticed when using setInterval() with objects, it accepts this:
setInterval(function(){auto1.increaseValue(s);}, auto1.interval);
Where auto1 is an object from a class.
However, the program throws an error when I put an object or object of an array of another object inside the function.
Ex.
let index = this.arrayForItems.length-1;
setInterval(function(){this.arrayForItems[index].increaseValue(s);header.innerHTML = s.value;}, this.arrayForItems[index].interval);
setInterval(function(){this.item.increaseValue(s);header.innerHTML = s.value;}, this.item.interval);//Where item is the object inside object shop
But this works.
let index = this.arrayForItems.length-1;
let referenceToPurchase = this.arrayForItems[index];
setInterval(function(){referenceToPurchase.increaseValue(s);header.innerHTML = s.value;}, referenceToPurchase.interval);
Why is this so?
This question already has answers here:
Explain the encapsulated anonymous function syntax
(10 answers)
Why are parentheses required around JavaScript IIFE? [duplicate]
(3 answers)
Closed 2 years ago.
Why if I have
function(){...}()
does not work while when I put inside brackets like
(function(){...}())
it works?
This question already has answers here:
JavaScript - Why is this function declaration created in a function expression "undefined"?
(3 answers)
javascript named function expressions - scope accessibility [duplicate]
(4 answers)
What is the scope of variables in JavaScript?
(27 answers)
Closed 2 years ago.
document.getElementById('game').addEventListener('click', function startGame() {
console.log('Game is starting!'); // name of the function is given just for debugging purposes
});
What is the scope of the function startGame?
Where is this function accessible(Where it can be called) ?
This question already has answers here:
What does (function($) {})(jQuery); mean?
(6 answers)
What is the (function() { } )() construct in JavaScript?
(28 answers)
Closed 5 years ago.
I see in the jQuery code this structure but I don't know the name and how use correctly.
(function($) {
...
})(jQuery);
I suppose it's a form of past arguments to the function.
this will execute the function immediately (immediately invoked)
This question already has answers here:
How to pass extra parameter to event handling callback?
(2 answers)
Pass an extra argument to a callback function
(5 answers)
Closed 5 years ago.
I have a function where I would like to call classList methods dynamically, something like this:
function expand(action) {
searchContainer.classList[action]("expanded");
}
button.addEventListener("click", expand('add'), false);
searchContainer.addEventListener("onblur", expand('remove'), false);
But not sure how can I do that?