Javascript不兼容/不一致 [英] Javascript Incompatibilities/Inconsistencies

查看:92
本文介绍了Javascript不兼容/不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在几周内做一个演示,并且想知道:在开发时你需要注意的十大Javascript不兼容性是什么?你绊倒了什么?我可以从一开始:

I'm looking to do a presentation in a couple of weeks and was wondering: What are the top ten Javascript incompatibilities that you look out for when developing? What trips you up? I can start with one:

var somevar = {
 'internet': 'explorer',
 'hates': 'trailing',
 'commas': 'in',
 'json': 'code', // oh noes!
}

有哪些其他常见问题无法解决或未解决使用像jQuery或base这样的框架?

What are some other common gotchas that can't or aren't fixed by using a framework like jQuery or base?

推荐答案

var x = new Boolean(false); if(x)... else ...;

var x = new Boolean(false); if (x) ... else...;

是否采用'if'或'else'分支?

Is the 'if' or 'else' branch taken?

var x =hi,y = new String(hi);

var x = "hi", y = new String("hi");

typeof(x)和typeof(y)是什么?

what is the typeof(x) and typeof(y) ?

编辑:..

parseInt(017)产生15(八进制)而不是17

parseInt("017") produces 15 (octal) instead of 17

'错误'对象是从IE到Firefox的不同签名。

The 'Error' object is a different signature from IE to Firefox.

当使用对象作为hashmap时,你需要使用object.hasOwnProperty(key)来确保不通过原型链继承该属性。

When using objects as hashmap's, you need to use object.hasOwnProperty(key) to ensure that the property is not inherited through the prototype chain.

这篇关于Javascript不兼容/不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆