Javascript: Inconsistency when assigning a named function to a variable (named function expression)



Can anyone explain the difference in behaviour between Internet Explorer and Firefox in regards to the below:


var myNamespace = (function () {
var exposed = {};
exposed.myFunction = function myFunction () {
return "Works!";
}
console.log(myFunction());
// IE: "Works!"
// Firefox: ReferenceError: myFunction is not defined
console.log(exposed.myFunction());
// IE: "Works!"
// FF: "Works!"
return exposed;
})();
console.log(myNamespace.myFunction());
// IE: "Works!"
// FF: "Works!"

In interne


View Replies

Related to : Javascript: Inconsistency when assigning a named function to a variable (named function expression)


Calling a JavaScript function named in a variable
Category : Javascript

I have a JavaScript variable which contains the name of a JavaScript function. This function exists on the page by having been loaded in and placed using $.ajax, etc.


Can anyone tell me how I would call the javascript function named in the variable, please?


The name of the


View Replies


Call JavaScript function named in a string variable - how?
Category : ASP & ASP.net

Greetings,

 I need to call JavaScript function "B" based on a string value passed to JavaScript function "A".  JavaScript function "B" resides in an external library and is not present on the page wher


View Replies


What determines if a JavaScript function is a named anonymous function versus a, um, regular function?
Category : Javascript

Reading "A re-introduction to JavaScript" I noticed something interesting about functions:


The name provided to an anonymous function as above is(or at least should be) only available to the function's own scope.


Entering some things based on the code in the tutorial at


View Replies


Why would you assign a function to a variable instead of declaring a named function?
Category : Web Design

Why would I do this:


var myfunc = function() { /* code */ };
...
myfunc();

instead of this:


function myfunc() { /* code */ }
...
myfunc();

Are there any benefits of using one over the other? I have seen bo


View Replies


why would I return a named function (object) from a javascript function?
Category : Javascript
Maybe I'm missing something obvious ... I've just started working with JavaScript, and when looking through an article about unit testing JavaScript with Jasmine, I came across this code:function Convert(number, fromUnit) { var conversions = { distance : { meters :

View Replies


PHP Function named after the Value of a Variable
Category : Web Design

I have a PHP function that I need to create that executes PHP or HTML Code that is stored in a variable. That's one problem. Another problem is the fact that the function will be created multiple times and will need a unique name so I've named it after $title but I'm not sure if this


View Replies


Calling a function named in a variable.
Category : C & C++ & C#
I looked. I really did. Anyway...
Is it possible in c++ to call a function the name of which is contained in a variable?
Psuedo code (which is a euphemism for I can't write code that works):
Code:
View Replies


call a function named in a string variable in c
Category : Programming Languages

I want to call a function using a variable.Is it possible in C??
Actually, what I want to do is, get the function name from the user and store it in a variable say var. Now I want to call the function that has its name stored in the variable var. Can anyone tell me how this can be done in C?


View Replies


Why would I assign a function declaration to a named variable?
Category : Web Design

Edit: it's NOT an assignment of a function declaration to a named variable - check the accepted answer. Leaving title as it is because other people might make the same error as me.


While reading Paul Irish's infinitescroll jquery plugin code, I stumbled again and again over the follow


View Replies


Calling named variable by passing name to function
Category : Development
Im pretty rusty at Javascript - this should be a simple one.
I have a form with a select field that runs a function onchange
<.....onchange="setProject(this.value)" ...>
In my script I have Javascript that looks more or less like this:
var ABCD = "This is the

View Replies


2012 / 2017 Copyrights BigHow , All Rights Reserved .