Questions tagged [function-expression]
100 questions
1
vote
1 answer
JavaScript: Change function declarations to expressions at legacy code
I'm busy with refactoring of legacy code. Here I can see that for functions used both declarations and expressions. I know that declarations hoisted, expressions are work at time step-by-step execution. There are also NFE but I can't use them…

Viacheslav Kondratiuk
- 8,493
- 9
- 49
- 81
1
vote
1 answer
Calling an function expression with a name outside
I have function expression in javascript like this:
(function () {
.
//code here
.
.
}());
how do I call it from somewhere else like from another function.
I have tried this.
var bind = (function () {
//code here...//
}());
and…

Salim
- 143
- 11
1
vote
1 answer
Do double-named methods create side-effects?
I recently ran into a couple of libraries that define methods on objects as follows:
var someObject = {
myMethod: function myMethod(args){ /* implementation */ }
};
Can someone maybe explain to me what the use of the double naming is? I…

Steven
- 1,566
- 2
- 16
- 38
1
vote
1 answer
Why can I not pass a "function declaration" as an argument in an event handler function with JQuery?
Why isn't this working using function declaration, but it's working perfectly using function expression?
Assuming that the only difference is how the browser loads them into the execution context.
function foo(event){
console.log('in…

Pompeyo
- 1,459
- 3
- 18
- 42
1
vote
1 answer
JavaScript function expression
The following line:
var A = function def() {alert();};
Only A() invokes the function. def() does not. Why is it so? Isn't the left side a function delaration?

Boyang
- 2,520
- 5
- 31
- 49
1
vote
2 answers
What is the scope of a variable defined within a function expression in strict mode?
As I understand, when a variable is defined it gets attached to the 'closest' local scope via this.
If no scope is set locally, the closest scope becomes window.
In strict mode, however, the local scope is set to undefined instead of window, as…

qodeninja
- 10,946
- 30
- 98
- 152
1
vote
1 answer
All function expressions suddenly arent recognized as functions
I have a massive javascript file with many function expressions. All of a sudden console gives me the following errors:
In IE
The value of the property 'myFunc' is null or undefined, not a Function object
In Firefox
TypeError: myFunc is not a…

Jonathan Eckman
- 2,071
- 3
- 23
- 49
0
votes
2 answers
Function Expression vs Function Declaration in Javascript Decorators
I have a problem understanding how different ways to create a function are affecting decorators. I am trying to create a decorator that will allow me to count how may times function was called:
function counter(func) {
wrapper =…

Иван Бельков
- 3
- 1
0
votes
1 answer
On the fly function expression doesn't throw error when triggering with first class
I am learning Javascript and I came across these concepts of function expressions & first class functions.
While I do understand their definition, I am unable to understand why my code behaves the way it does.
I have a first class function which…

M Navneet Krishna
- 639
- 5
- 14
0
votes
1 answer
how to conditionally include or exclude statements from function expression
i have 2 different javascript environments and want to create a library usable on both. to do that i want to use higher order functions to generate my functions, like so
try {
Maptool.chat.broadcast("")
var myFunc1 =…

ether
- 1
- 2
0
votes
2 answers
JavaScript hoisting for function expression and function declaration
I am learning hoisting in JavaScript and practicing some examples.
In an example I am confused of it's output.
Here is the example code:
var f = function(){
console.log("Expression");
}
function f(){
console.log("Declaration");
}
f();
The…
0
votes
1 answer
Dart/Flutter arrow function expression confusion
I'm confused with arrow syntax in this Navigator implementation:
Navigator.push(
MaterialPageRoute(
context,
builder: (context) => aWidgetConstructor()
)
)
From what I guess, the 4th line is similar to
Widget build(Buildcontext…
0
votes
0 answers
React with Typescript: Passing Down Functions as Props in Function Expression Components
I'm currently learning how use React with Typescript and came across this situation: I need to pass down a function to a child component as a prop, and let's say this is a quite complicated function with a punch of parameters. What do you think…

Nam
- 554
- 4
- 11
0
votes
1 answer
Is this an arrow function declaration? Is there such a thing?
I am looking into function expressions vs function declarations using arrow functions.
I am thinking this is an arrow function expression:
const johan = greeting = () => {
console.log("Hi from arrow function expression");
};
and that this is an…

Johan Berglund
- 7
- 3
0
votes
3 answers
Difficulty Iterating Through Function Call - First Class Functions
The code I have provided executes properly, however as you will see it offers refreshments to each guest repeatedly before moving on to the next guest.
I'm scratching my head as to how I can alter my code, in an efficient way, so that each customer…

Lil' Big Boy
- 21
- 6