Posts Tagged ‘逐句学英文’



A variable is a name associated with a value; we say that the variable stores or contains the value.

Variables allow you to store and manipulate data in your programs.

For example, the following line of JavaScript assigns the value 2 to a variable named i:
例如,下面一行JavaScript代码将数值 2 赋给了一个名为 i 的变量
i = 2;

And the following line adds 3 to i and assigns the result to a new variable, sum:
下面的代码将3加到i上,然后把结赋给了一个新的变量 sum:
var sum = i + 3;

阅读全文 »



An array is a collection of data values, just as an object is.

In JavaScript, you retrieve a value from an array by enclosing an index in square brackets after the array name.
在 JavaScript 中,要获取数组中的某个值,可以使用数组名,在其后加上用方括号封闭起来的小标值即可。

For example, if an array is named a and i is a nonnegative integer, a[i] is an element of array.

阅读全文 »



An object is a collection of named values.

These named values are usually referred to as properties of the object.

For example, if an object named image has properties named width and height, you can refer to those properties like this:


Properties of objects are, in many ways, just like JavaScript variables; they can contain any type of data, including arrays, functions, and other objects.
对象的属性在很多方面都跟 JavaScript 的变量相似,属性可以是任何类型的数据,包括数组、函数和其他对象。

Thus, you might see JavaScript code like this:
所以,读者有可能会见到如下的 JavaScript代码:

This code refers to the button property of an object that is itself stored in the myform property of an object named document.

When a function value is stored in a property of an object, that function is often called a method, and the property name becomes the method name.

Objects in JavaScript can serve as associative arrays; that is, they can associate arbitrary data values with arbitrary strings.
JavaScript 中的对象可以作为关联词组使用,因为它们能够将任意的数据值和任意的字符串关联起来。

阅读全文 »



Although a function is defined only once, a JavaScript program can execute or invoke it any number of times.

A function may be passed arguments, or parameters, specifying the value or values upon which it is to perform its computation, and it may also return a value that represents the results of that computation.

JavaScript implementations provide many predefined functions, such as the Math.sin() function that computes the sine of an angle.
JavaScript 的实现提供了许多预定义函数,如 Math.sin() ,它用于计算角的正弦值。

JavaScript programs may also define their own functions with code that looks like this:
JavaScript 程序也可以定义自己的函数,代码如下:

function square(x)//定义了一个名为square的函数,它指定了一个参数x
return x*x; // 返回参数x的平方(值)

Once a function is defined, you can invoke it by following the function’s name with an optional comma-separated list of arguments within parentheses. The following lines are function invocations:

y = Math.sin(x);
y = square(x);
d = compute_distance(x1,y1,z1,x2,y2,z2);

An important feature of JavaScript is that functions are values that can be manipulated by JavaScript code.
JavaScript 的一个重要特性是 JavaScript 代码可以对函数进行操作。

The fact that functions are true values in JavaScript gives a lot of flexibility to the language.
JavaScript 中的函数是真正的数值,这一点给语言带来了很大的灵活性。

It means that functions can be stored in variables, arrays, and objects, and it means that functions can be passed as arguments to other functions.

阅读全文 »

Page 1 of 212
Powered by SinaSAE | Theme by ck web design | TOP 顶部
Copyright © 崔凯 All rights reserved. 蜀ICP备12025891号.