Search within TutorialsPark

Javascript Advanced Functions


Learn Some new Advanced Techniques used for creating Functions


Javascript Advanced Function : Safe Scope Functions.

Safe Scope Constructors are created using functions which first checks to ensure that the this object is an instance of the correct type before execution is carried out.

In the demo below, a constructor myPhone has been used to add an if statement to ensure that the object this is an instance of myPhone

Example: Javascript Functions: Safe Scope Functions.

Give it a TRY! » Note: If this is not an instance of the function, then the constructer gets called again with new operator.


JavaScript Function: Function Currying

The Function Currying is an technique wherein a function is created with one or multiple arguments already set.

The idea is to use a closure to return a new function, and this new function sets some arguments which is passed when the function is called.

In the below demo, two functions multiply() and curryMultiply(), but the function curryMultiply() is same as Multiply() only difference being that it sets the first argument as 10.

Example: JavaScript Function : Function Currying

Give it a TRY! » Note: The function curried is used to arrange the arguments of the returned function in an ordered manner.