javascript – 我们可以通过脚本删除HTML5 Canvas标签的“getContext”属性吗?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 我们可以通过脚本删除HTML5 Canvas标签的“getContext”属性吗?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1822字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 我们可以通过脚本删除HTML5 Canvas标签的“getContext”属性吗?](/upload/InfoBanner/zyjiaocheng/720/1c1f9b98c3bd48e48f51ae49bfcd24ee.jpg)
有一个HTML5 conformance test suite与HTMLCanvasElement的原型测试.
Safari,Firefox测试失败,但Windows 7上的Opera测试失败.
测试有一个脚本,它试图删除HTMLCanvasElement的getContext属性,并且进一步尝试读取getContext应该给出undefined.
delete window.HTMLCanvasElement.prototype.getContext;
_assertSame(window.HTMLCanvasElement.prototype.getContext, undefined, "window.HTMLCanvasElement.prototype.getContext", "undefined");
WebKit(Safari)的此测试失败,因为getContext属性具有DontDelete属性,因此它不允许脚本删除此属性.
HTML5规范中是否有任何描述说脚本删除getContext属性是有效的?
解决方法:
根据我的理解,在WebIDL中描述了getContext方法中ES3中的[[DontDelete]],ES5中的[[Configurable]]的可配置性 – 与任何其他CanvasRenderingContext2D方法一样.
看看“Interface Prototype Object”部分,其中说:
There must exist an interface prototype object for every interface defined, regardless of whether the interface was declared with the [NoInterfaceObject] extended attribute. The interface prototype object for a particular interface has properties that correspond to the attributes and operations defined on that interface. These properties are described in more detail in sections 4.5.5 and 4.5.6 below.
在4.5.6,您可以看到:
For each unique identifier of an operation defined on the interface, there must be a corresponding property on the interface prototype object (if it is a regular operation) or the interface object (if it is a static operation), unless the effective overload set for that identifier and operation and with an argument count of 0 (for the ECMAScript language binding) has no entries.
The characteristics of such a corresponding property are as follows:
The name of the property is the identifier.
The property has attributes { [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
注意“[[Configurable]]:true”位(强调我的).
内容总结
以上是互联网集市为您收集整理的javascript – 我们可以通过脚本删除HTML5 Canvas标签的“getContext”属性吗?全部内容,希望文章能够帮你解决javascript – 我们可以通过脚本删除HTML5 Canvas标签的“getContext”属性吗?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。