get: function(){ return name; },
set: function(value){ name = value; }
}
约翰同学的讲解:http://ejohn.org/blog/ecmascript-5-objects-and-properties/
支持:无
替代/过渡:Object.defineProperties其实相当于jQuery.extend,用来实现Mixin
ECMAScript 5 Getters and Setters
python和ruby里都有的属性访问方法
obj = {
get innerHTML() { return …; },
set innerHTML(newHTML) { … }
};
MDC文档:https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters
支持:Firefox 2.0+, Safari 3.0+, Google Chrome 1.0+, Opera 9.5+
替代/过渡:
非标准,Firefox1.5里的旧方法
HTMLElement.prototype.__defineGetter__("innerHTML", function () {});
HTMLElement.prototype.__defineSetter__("innerHTML", function (val) {});
支持:Firefox 2.0+, Safari 3.0+, Google Chrome 1.0+, Opera 9.5+
标准
Object.defineProperty(document.body, "innerHTML", { get : function () {} });
MSDN文档:http://msdn.microsoft.com/en-us/library/dd229916(VS.85).aspx
支持:IE8+ (只能对DOM使用)
ECMAScript 5 Strict Mode
ES5的严格模式,删除了旧版本中容易引起问题的元素,并且会显式的报错,方便调试
"use strict"; //以下情况下抛出异常
//对未定义的变量赋值
//操作被设置为不可写,不可配置或不可扩充的属性
//删除变量,函数,参数
//在对象直接量里重复定义属性
//eval做关键字,在eval的字符串里定义变量
//覆写arguments
//使用arguments.caller和arguments.callee(匿名函数必须具名才能引用自己)
//(function(){ … }).call( null ); // Exception
//使用with
约翰同学的讲解:http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
支持:无
替代/过渡:……从现在开始养成严谨的编程习惯
ECMAScript 5 其他新特性
传递函数的引用时,绑定this
Function.prototype.bind(thisArg, arg1, arg2….) /
支持:无
替代/过渡:prototype http://www.prototypejs.org/api/function/bind
ISO-formatted dates
Date.prototype.toISOString() // Prints 2009-05-21T16:06:05.000TZ
支持:无
替代/过渡:datejs http://code.google.com/p/datejs/
String.prototype.trim()
支持:Firefox3.5
替代/过渡:各种正则实现 http://blog.stevenlevithan.com/archives/faster-trim-javascript
===================废话又开始的分割线=======================









