MooTools Functions - MooTools

What is MooTools Function?

Functions in MooTools are a concept from JavaScript. We already know how to use functions in JavaScript. Usually, it's far better to keep the function outside the page body in the script tag. In MooTools, we follow the identical sample. Here, you may design your own function according to the requirement. We now have to call all the user-defined functions in the Dom ready characteristic.

Take a look at the following syntax to understand how to use the generalized function in MooTools.

Syntax

Basic structure

There are a few basic ways to define a function in MooTools. There may be no difference between the function syntaxes of JavaScript and MooTools, however, the difference is in calling a function. Let us take a small instance that defines a function named demo_function. Check the subsequent code.

Example

You will receive the following output −

Output

MooTools function

Single Parameter function

You could additionally create a function that accepts a parameter. To use parameters with functions, you want to add a variable name within the parenthesis. Once you offer it, the variable is available inside for use. Allow us to take an instance that defines a function that takes a single parameter and prints a message along with the parameter.

Take a look at the following code.

Example

You will receive the following output −

Output
MooTools function 2

Returning a value

Whenever you want to use the end result of one function as input for another variable, you're required to apply the return value for that function. You could use the return keyword for returning a value from the function. Let us take an example that defines a function that will accept two parameter values and return the sum of those two parameters. Take a look at the subsequent code.

Example

You will receive the following output −

Output

MooTools Function 3

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MooTools Topics