不兼容ECMAScript部份说明
出自嗶哩嗶哩百科
目录 |
for...in
- for..in的实现改为以Function#foreach函数完成
示例
a={a:"b",b:"c"}; foreach(a,function(key,obj){ trace(key+":"+obj); });
函数默认值指定
- 使用if判断是否为undefined后指定值
示例
function a(a){ if (a==undefined) a=1; trace(a); } a();
prototype
- 无法使用prototype关键字
- 使用以下方式创建类
示例
function newObject(){ var newObj = {}; newObj.init=function(){ this.initValue=1; }; newObj.output=function(){ trace(this.initValue); }; return newObj; } var test = newObject(); var test2 = newObject(); test.init(); test.output(); test2.output();
new
- 目前不支持使用new关键字 复制使用函数Function#clone
- 创建Object请使用 var tp={};
- 创建Array请使用 var tp=[];
- 以下示例将复制一个类
示例
var a={test:2}; var b=clone(a); a.test=1; trace(b.test);
函数返回的对象不能继续调用函数
- 由于函数与成员的优先级问题 调用需要使用括号
示例
var a={}; a.b=function(){return a;}; (a.b()).b();