2012-08-08 57 views
0

Here它描述了如何使用Firebug/FF Web控制台检查innerHTML属性是否可配置和可枚举。 如何检查charCodeAt功能相同? Object.getOwnPropertyDescriptor(HTMLElement.prototype,"charCodeAt") 返回undefined如何检查charCodeAt()是否可配置

+0

它说它不能在Firebug那里工作。确保你使用FF web控制台而不是萤火虫 – PitaJ 2012-08-08 22:09:38

回答

4

.charCodeAt() method属于Strings,不HTMLElement

Object.getOwnPropertyDescriptor(String.prototype,"charCodeAt") 
+0

它直接在'String'上,而不是'String.prototype'。 – 2012-08-08 22:09:56

+0

@amnotiam很确定它的原型:P你在想'fromCharCode' – Esailija 2012-08-08 22:10:23

+0

@amnotiam - 你确定吗?当我[试用它](http://jsfiddle.net/nnnnnn/7KPzq/)与'String.prototype'工作,但'字符串'不。 (在Chrome中测试) – nnnnnn 2012-08-08 22:11:24

2

这是因为charCodeAt不是HTMLElement的方法,它在String -object的方法(或者更确切地说,它的原型)

Object.getOwnPropertyDescriptor(String.prototype,"charCodeAt") 
+0

@amnotiam它在原型中,只检查'String'在Chrome中返回undefined – GNi33 2012-08-08 22:11:40