About 283,000 results
Open links in new tab
  1. Define a function within another function in JavaScript

    The closure keeps the scope of bar() contained, returning the new function from the self-executing anonymous function sets more visible scope to foo(). The anonymous self-executing function is run exactly once, so there is only one bar() instance, and every execution of foo() will use it.

  2. javascript create function - Stack Overflow

    Feb 16, 2011 · The difference between var fun = function() {} and function fun() {} is that in the first case it is stored in the variable fun. To call the function, you have to call fun(). Having it in a variable lets you pass the function around. You can create objects by using functions

  3. javascript - Proper use of const for defining functions - Stack …

    2. Fat arrow syntax is not shorter unless your function can be an expression. function f(x, y) {is 18 characters, const f = (x, y) => {is 21 characters, so 3 character longer. 3. Keeping this binding only matters if the functions are defined inside a method (or other function which has meaningful this). At the top level script it is pointless.

  4. javascript - Creating functions dynamically in JS - Stack Overflow

    function behaviour_1(){ this.x++; } function behaviour_2(){ this.y++; } My question is, now that I have the code loaded, how can I execute it? I would like to create a function with an unique name for each code 'node', and then call them from the game logic, but I don't know if this is possible (Since you can load more JS code from the HTML ...

  5. Passing an array as a function parameter in JavaScript

    May 18, 2010 · I'd like to call a function using an array as parameters: const x = ['p0', 'p1', 'p2']; call_me(x[0], x[1], x[2]); // I don't like it function call_me (param0, param1 ...

  6. javascript - How to create a jQuery function (a new jQuery method …

    Aug 23, 2012 · // to create a jQuery function, you basically just extend the jQuery prototype // (using the fn alias) $.fn.myfunction = function { // blah }; Inside that function, the this variable corresponds to the jQuery wrapped set you called your function on. So something like:

  7. Is there a way to create a function from a string with javascript ...

    Oct 4, 2011 · If you have a function expression that is in string form and you want to make it a function, then you need to include a return statement in the string you pass to new Function. const strFn = "const sum = (a, b) => a + b" const newFn = new Function(`${strFn}; return sum`)(); console.log(newFn(2, 3)) // 5

  8. oop - JavaScript private methods - Stack Overflow

    Sep 11, 2008 · To make a JavaScript class with a public method I'd do something like: function Restaurant() {} Restaurant.prototype.buy_food = function(){ // something here } Restaurant.prototype.use_restro...

  9. javascript - Increment value each time when you run function

    Feb 17, 2014 · So I need a function which increments the value of a variable say n=0. When ever the function runs, the value of this varible must be incremented and it should not be equal to 0 again. For example consider the following code : function increment(){ var n = 0; n++; return n; } Now everytime you run this function you get a value of 1.

  10. javascript - Functions inside objects - Stack Overflow

    I know the title is vague but I didn't know what to write. In javascript, I know how to write functions that will be called like this : argument1.function(argument2); Here is the fiddle demonstr...

Refresh