Create a js function

Functions in a script tag Once created, all the script tag can be used later in the function

Naming function definition

Functions are objects

function abc( ){



was fn = ABC;

abc( ); //a

fn (); // a

Anonymous function definitions

var fn = function () {// set to variable


fn( ); //b


var obj = {



        c: function () {// set to the properties of the object




// anonymous function with no name, can be set to a variable or set to a property of the object

Naming function can be performed before and after the function definition, anonymous functions can only be executed after the function definition.


// self-executing anonymous function

Disadvantages: can only be executed once, can not be called again

(function( ){


})( );

The constructor is defined

var fn = new Function ( "parameter 1", "parameter 2", ..., "Function The statements")

// foregoing is all the parameters of this function is created, the content is the last function block execution statement,

Require that all content must be strings.

Disadvantages: slow speed is low efficiency, because all you want to convert a string to code.

Guess you like