Posts Tagged ‘逐句学英文’

逐句学英文-变量

Variablesˈvɛəriəbl变量

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;

阅读全文 »

逐句学英文-数组

Arraysarray数组

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.
例如,如果一个数组名为a,i是一个非负整数,那么a[i]就是一个数组元素。

阅读全文 »

逐句学英文-对象

Objectsˈɔbdʒikt对象

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:
例如,如果一个名为image的对象有一个名为width和一个名为height的属性,我们可以使用如下方式来引用这些属性:

image.width
image.height

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代码:
document.myform.button

This code refers to the button property of an object that is itself stored in the myform property of an object named document.
这里引用了一个对象的button属性,而这个对象本身又存储在对象document的myform属性中。

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 中的对象可以作为关联词组使用,因为它们能够将任意的数据值和任意的字符串关联起来。

阅读全文 »

逐句学英文-函数

Functionsˈfʌŋkʃən函数

Although a function is defined only once, a JavaScript program can execute or invoke it any number of times.
虽然函数只定义一次,但是JavaScript程序却可以多次执行或调用它。

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);
move();

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号.