您的位置:首页 > Web前端 > JavaScript

JavaScript_A Beginner's Guide - Understanding Functions - 09/22/2012

2012-09-23 19:46 399 查看
Functions can make your scripts more portable and easier to debug. This chapter covers the basics of using functions.

A function is basically a little script within a larger script. Its purpose is to perform a single task or a series of tasks. What a function does depends on what code you place inside it.

Why Functions Are Useful

Functions help organize the various parts of a script into the different tasks that must be accomplished. By using one function for writing text and another for making a calculation, you make it easier for yourself and others to see the purpose of each section
of the script, and thus debug it more easily.

Another reason functions are useful is their reusability. They can be used more than once within a script to perform their task. Rather than rewriting the entire block of code, you can simply call the function again.

To declare a function, you use the reserved word function, followed by is name, and then a set of parentheses:

function functionname()


The reserved word function tells the browser that you are declaring a function and that more information will follow.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: