1

Possible Duplicate:
“Usual” functions vs function variables in JavaScript
whats the difference between function foo(){} and foo = function(){}?

i don't really see the difference between those two functions :

window.send_to_editor = function(html){

and

function send_to_editor(html) {

they both have a name to call them, although the first one is considered to be anonymous ?

Thanks for your answer

Community
  • 1
  • 1
Paul
  • 6,108
  • 14
  • 72
  • 128
  • 2
    @Michael: This might be subject to interpretation. The first function is definitely a nameless function which I would say it the same as an anonymous function. The name of the variable the function is assigned to is not the name of the function. You can assign the same function to multiple variables. – Felix Kling Mar 19 '12 at 16:37

1 Answers1

1

A few things...

  1. The first is creating an anonymous function and then assigning it to a non anonymous member...
  2. The second is actually declaring the function, and declared functions are always hoisted

To add to your confusion.. this is what hoisting means... declared functions are "hoisted" to the top so the following is valid.

//call it
funcOne();

//declare it
function funcOne() {
    alert("Why am I working? I thought javascript was top down?!?!?");
}

Also, you can name function expressions (for the purpose of calling them recursively). This is also valid

var funcOne = function internalName() {
    internalName();
};

I usually prefer creating functions via assignment/expression, mainly because it more accurately describes that functions are first class values, and does not incidentally create possible confusion via hoisting behavior.

jondavidjohn
  • 61,812
  • 21
  • 118
  • 158