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:
The reserved word function tells the browser that you are declaring a function and that more information will follow.
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.
相关文章推荐
- JavaScript_A Beginner's Guide - Conditional Statements and Loops - 09/23/2012
- JavaScript_A Beginner's Guide - Introduction to JavaScript - 09/19/2012
- JavaScript_A Beginner's Guide - Understanding variables - 09/21/2012
- JavaScript_A Beginner's Guide - Using an external JavaScript file - 09/20/2012
- selenium 1.0 Testing Tools:Beginner's guide 已完成- selenium 1.0初学者指南
- Microsoft Exchange Server 2007: A Beginner's Guide (Paperback), (Network Professional's Library) Aug.2007.eBook-BBL
- Objective-C Beginner's Guide
- 《MooTools 1.2 Beginner's Guide》
- Objective-c Beginner's Guide
- cocos2d-x by Example Beginner's Guide 第5章 Rocket Through 之 粒子系统
- Mastering Debugging in Visual Studio 2010 - A Beginner's Guide
- cocos2d-x by Example Beginner's Guide 第5章 Rocket Through
- Ogre1.7 Beginner's guide
- Mastering Debugging in Visual Studio 2010 - A Beginner's Guide
- O'Reilly JavaScript and DHTML Cookbook
- VB.NET Developer's Guide
- Note on <Zend Framework - A Beginner's Guide> - 04 使用Doctrine初体验
- What's "new" in JavaScript?
- QS0002-2012 瞿氏标准(Qu's Standards)IT从业人员工资计算标准