下面的代码在chrome、firefox中执行时,不会出现错误。但 safari 会抛出 TypeError: Attempting to Changeconfigurable attribute of unconfigurable property。 我不明白如果 src 不可配置,那么为什么 chrome 和 firefox 不会出现错误。
Object.defineProperty(iframe, 'src', {
writable: false, configurable: true
});
Safari 版本 11.0.1
PS - 我知道更改现有的不可配置属性会引发此错误,但为什么 chrome 和 firefox 不这样做
最佳答案
I don't understand if src is inconfigurable then why don't error comes for chrome and firefox
因为不同的浏览器实现DOM的方式不同。 Chrome 和 Firefox 似乎没有将 src
标记为不可配置。 Safari 显然是这样的。另请注意,在 Chrome 上(至少),src
属性是继承的并且具有 getter/setter,因此在 iframe
上调用 defineProperty
< em>instance 将在该实例上创建一个新属性,而不是修改以前从原型(prototype)继承的属性的行为。 (我没有检查 Firefox 或 Safari。)
如果您想与 Safari 兼容,则需要以不同的方式满足您的基本要求。
关于javascript - 类型错误 : Attempting to change configurable attribute of unconfigurable property of iframe's src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50219059/