Questions tagged [function-expression]

92 questions
0
votes
1 answer

Function expression as argument for other function call

I am quite new to javascript and I am trying to understand the function expression as argument for other function call. Here is one example that use mongoose to do a search: app.get('/auth/:id', (req, res) => { var db = req.db; …
xc2333
  • 49
  • 1
  • 7
0
votes
1 answer

How can I set named function expressions on my Dropzone options?

I have multiple Dropzones in my project that are all very similar. On one of them, I had to create a minimum file width, but the video Dropzone doesn't work with the file width code. I ended up having to create a separate options call for each…
Rachel Martin
  • 398
  • 4
  • 16
0
votes
0 answers

Why this function expression execute when first assigned?

I suddenly feel so confused about this example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_setinterval_clearinterval in the script, var myVar = setInterval(myTimer, 1000); function myTimer() { var d = new Date(); var t =…
Ying
  • 233
  • 3
  • 16
0
votes
0 answers

Why does the bind method when used as a value in an expression doesn't work?

Treating the bind method for JS functions as a value makes it behave unexpectedly when used in conjunction with both the ternary and short-circuit operators. Why does this happen? I tried to make a utility function shorter by using the ternary…
0
votes
0 answers

Is it correct to say that the function keyword is essentially obsolete in JavaScript?

I want to see if my understanding is correct: the functionality of the function keyword was divided up between classes and Arrow functions in es6. First, in the case of anonymous functions, I see no advantage in using function() {...} over Arrow…
0
votes
0 answers

Does functions expressions assume the this of the lexically enclosing function context?

I confident about that function declarations does not has lexical context and arrow function it does have, but I am confused if function expression does ? According to what I read it doesn't but in the following example it works fine both ways(…
CodeHip
  • 307
  • 4
  • 14
0
votes
1 answer

AngularJS Provider doesn't accept ES6 function declaration

I've been trying to rewrite some code of ours to comply with ES6 and have encountered the following issue. angular.js:63 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:pget] Provider 'books' must…
Jimenemex
  • 2,836
  • 2
  • 13
  • 39
0
votes
0 answers

What are the pros/cons and best practices for creating functions for a React Component class?

Both of these classes do the same thing, but ClassA seems redundant because of the binding you have to do every time you declare a function and ClassB doesn't seem as clean as ClassA because of the differences in types of function creations. class…
0
votes
2 answers

Function Expression Parameter is not assigned a value, but has a value

I'm hoping someone can explain how the the below function expression works. The parameter 'p' has not been assigned a value, however it is used in the body of the function for calculations (defining the "angle" and "tail" variables) and as an…
0
votes
2 answers

Is it possible to have parameters for anonymous function?

Given var stuffs = [ { id : 1, name : "orange"}, { id : 2, name : "apple"}, { id : 0, name:"grapes"} ]; var filterMethod1 = new function(o){return (o.id>=1);}; // this gives undefined error for o function filterMethod2(o) {return…
0
votes
2 answers

Passing parameter to method in array.map

How can i pass parameter to a method which is passed as parameter inside an array. map method. var result = [1,2,3]; var updatedResult = result.map(modifierMethod); function modifierMethod(cellValue){ return cellValue* dynamicValue} I want to pass…
starhunter
  • 145
  • 8
0
votes
0 answers

javascript function expression vs declaration

How is that possible that code below doesn't alert undefined? From my understanding only variables names declaration were hoisted and then on createWorkout() call it's should be undefined but it's not and works perfectly fine. var start = function()…
0
votes
1 answer

Function returns undefined in Javascript

Can not figure it out how to return value (string) from this function: function loadPage(url) { var xhttp = new XMLHttpRequest(); xhttp.open("GET", url, true); xhttp.send(); xhttp.onreadystatechange = function() { if…
0
votes
1 answer

Sinon spy on function expression

is it possible to make sinon spy on function expressions? Look this code for example. function one() { return 1; } function two() { return 2; } function three() { return 3; } function myMethod() { var n1 = one(); var n2 = two(); var…
Alejandro Nanez
  • 307
  • 2
  • 6
  • 14
0
votes
3 answers

lexical scopes for function expressions

If we divide the operation of javascript engine into compilation phase (where that whole lexical scope diagram is setup) Vs running phase (where code is executed using lexical scope setup in compilation phase), when is the scope for function…
noi.m
  • 2,622
  • 4
  • 28
  • 50