最近开始研究标准文档——ECMA-262, 9th edition标准 (http://www.ecma-international.org/ecma-262),这可以说是JavaScript的根本了,标准文章很庞大,希望通过研究能够了解更多JS的运行实质。之后会时不时的发布该文档的部分译文,供大家参考,也希望大家能指出翻译中的不妥之处,共同完善。
今天翻译了第四章的部分内容,大部分内容和我们平时看书时讲述的一样,这里就是看看实际标准的中的表述,这是无论书籍中怎么写,都不会改变的东西。
4 Overview
4.2 ECMAScript Overview
4.2.1 Objects
原文:Objects are created by using constructors in new expressions; for example, new Date(2009, 11) creates a new Date object. Invoking a constructor without using new has consequences that depend on the constructor. For example, Date() produces a string representation of the current date and time rather than an object.
译文:对象实例是通过“new”操作符创建,例如,new Date(2009, 11)创建了一个新的Date对象;操作一个构造器而不使用“new”操作符,将取决于对象的构造器函数,即运行构造器。例如,Date()操作,直接产生一个包含当前时间日期的字符串,而不是一个日期对象实例。同理,js里原生的对象,如String, Boolean这些,不使用new,直接运行,产生的值会根据其内部构造器函数而定,并不一定是相应的对象实例,如String,Boolean,Number, 这些有基本类型的对象,new操作下是对应的对象实例,非new则返回基本的数据类型;Array,RegExp这类,有没有new都会返回一个对应的对象实例。
原文:Every object created by a constructor has an implicit reference (called the object's prototype) to the value of its constructor's "prototype" property. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called theprototype chain. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.
译文:每一个通过构造函数创建的对象都默认引用(称为对象的原型)它的构造函数的一个叫做“prototype”属性的值。而一个原型会也会引用他的一个值为非null或null的原型,并且如此延续下去,这种连续引用就称之为“原型链”。当一个对象的属性创建一个引用时,这个属性所引用的名字,来自于原型链上第一个包含该名字的对象,换句话说,就是第一个直接声明该属性的对象;如果对象包含这个直接声明的属性,则这个名字的属性就将成为整个原型链上的引用源;如果对象上不包含这个直接声明的属性,则会顺着该对象的原型链不断地向上查找,直到顶层。
原文:In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, while structure, behaviour, and state are all inherited.
译文:在基于类的面向对象语言中(如java:译者加),通常,状态来自于实例,方法来自于类,而继承的仅仅是类结构和通用行为。而ECMAScript(JavaScript), 状态和方法来自于每个对象,而结构,行为和状态又都能够继承。(此处翻译的不是很明确,感觉表述的不是很准确,有待改进)
4.3 Terms and Definitions
4.3.3 object
原文:member of the type Object
NOTE:An object is a collection of properties and has a single prototype object. The prototype may be the null value.
译文: 对象是一组属性的集合,包含单一的原型对象,原型可以是null值。
4.3.4 constructor
原文:function object that creates and initializes objects
NOTE:The value of a constructor's prototype property is a prototype object that is used to implement inheritance and shared properties.
译文:构造函数是创建和初始化对象的一种函数对象。构造函数的prototype属性值是一个原型对象,该对象用来实现继承和属性共享。
4.3.5 prototype
原文: object that provides shared properties for other objects
NOTE:When a constructor creates an object, that object implicitly references the constructor's prototype property for the purpose of resolving property references. The constructor's prototype property can be referenced by the program expression constructor.prototype, and properties added to an object's prototype are shared, through inheritance, by all objects sharing the prototype. Alternatively, a new object may be created with an explicitly specified prototype by using the Object.create built-in function.
译文:原型为对象的其他实例提供共享属性,当构造函数创建对象实例时,该实例将默认引用这个构造函数的原型属性用于解析相应的属性引用。这个构造函数的原型属性可以通过“constructor.prototype”的表达式获得引用,并且所有添加到原型上的属性都将被共享,通过继承,所有的对象都将共享这个原型。而还有一种情况,一个新的对象可以通过“ Object.create”这个内部方法来自定义任意的原型进行创建。
4.3.10 undefined value
原文:primitive value used when a variable has not been assigned a value
4.3.11 Undefined type
原文:type whose sole value is the undefined value
译文:以上两点共同翻译为,"undefined"是一个初始化时未指定具体值的变量的默认初始值,而所有值仅为"undefined"的变量的类型,都为"Undefined"类型。(标准里明确的是,undefined值就是Undefined类型)。
4.3.12 null value
原文:primitive value that represents the intentional absence of any object value
4.3.13 Null type
原文:type whose sole value is the null value
译文:以上两点共同翻译为,"null"是表示不存在的任何值的对象的初始值,而所有值仅为为"null"的变量的类型,都为”Null"类型。(标准里明确的是,null值就是Null类型)。
4.3.28 function
原文:member of the Object type that may be invoked as a subroutine
译文:函数是Object类型(标准明确),并且可以当作子程序调用。
4.3.31method
原文:function that is the value of a property
NOTE:When a function is called as a method of an object, the object is passed to the function as its this value.
译文:做为属性值的函数,称为方法,当一个函数作为一个对象的方法被调用时,这个对象会将其"this"值传递给该函数。
更多内容,欢迎光临个人网站。