内置对象原型 [英] Builtin object prototypes

查看:124
本文介绍了内置对象原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本可以在

JaavScript中为内置对象的原型添加方法。我可以为String.prototype。*分配函数,用于

实例。我想向Node添加一个方法,但是当我尝试执行

时,下面的IE表示'''Node''未定义。 Mozilla就像我预期的那样工作。 Node是否在IE中调用了其他内容? IE不允许

操纵一些内置对象的原型吗?


Node.prototype.nt = function(){

返回this.nodeType;

}


Ari。


-

如果你可以赔钱,选举只算作免费和试验公平

投注结果。

解决方案



Ari Krupnik写道:


脚本可以在

JaavScript中为内置对象的原型添加方法。我可以为String.prototype。*分配函数,用于

实例。我想向Node添加一个方法,但是当我尝试执行

时,下面的IE表示'''Node''未定义。 Mozilla就像我预期的那样工作。



嗯,实际上Mozilla的工作原理 - 可能在一些

的情况下很方便 - 但是非预期的方式。

prototype是JavaScript对象的属性; DOM Node不是一个

JavaScript对象,它与说Object()

构造函数无关(就像说DIV元素与Array
;-)

IE通过行为机制公开base [element]接口。这个

的方式,你可以说每个<元素有AJAX接口或每个

< divacting作为媒体播放器。但是对于Node我真的不知道

建议什么,因为它不是(X)HTML / XML意义上的元素,它是

单位一等级以下。您是否尝试统一扩充页面上的每个元素?b $ b元素?你的实际目标是什么? (所以也许是一些解决方案

是可能的)。




Ari Krupnik写道:


脚本可以在

JaavScript中为内置对象的原型添加方法。我可以为String.prototype。*分配函数,用于

实例。我想向Node添加一个方法,但是当我尝试执行

时,下面的IE表示'''Node''未定义。 Mozilla就像我预期的那样工作。 Node是否在IE中调用了其他内容? IE不允许

操纵一些内置对象的原型吗?


Node.prototype.nt = function(){

return this.nodeType;

}



DOM有一个实现Node接口的基础对象,
$ b Gecko浏览器中的$ b它被称为节点并且你可以搞砸

原型。


IE没有Node对象,尽管你可以将DOM对象扩展到

使用行为进行了一些扩展:


< URL:
http://msdn.microsoft.com/library/de...o/creating.asp


>



-

Rob




" Ari Krupnik" < ar*@lib.aerowrote in message

news:86 ************ @ deb.lib.aero ...


脚本可以在

JaavScript中为内置对象的原型添加方法。我可以为String.prototype。*分配函数,用于

实例。我想向Node添加一个方法,但是当我尝试执行

时,下面的IE表示'''Node''未定义。 Mozilla就像我预期的那样工作。 Node是否在IE中调用了其他内容? IE不允许

操纵一些内置对象的原型吗?



节点不是内置对象,它是主机对象。 (或者至少,

在浏览器DOM中实现Node接口的所有对象都是主机

对象),并且不需要主机对象来促进修改

他们的原型,暴露原型(甚至有原型)或暴露

构造函数。


因此一些主机可能提供这些设施(如Mozilla所做的那样) )

和其他人可能没有(比如IE)。两种选择(以及

之间的所有内容)都完全符合javascript语言

规范,没有其他规范(例如W3C DOM及其

ECMAScript绑定)已尝试在Web浏览器上下文中对主机对象应用任何其他约束




Richard。


scripts can add methods to the prototypes of builtin objects in
JaavScript. I can assign functions to String.prototype.*, for
instance. I want to add a method to Node, but when I try to execute
the following IE says "''Node'' is undefined." Mozilla works as I
expected it to. Is Node called something else in IE? Does IE not allow
manipulating the prototypes of some builtin objects?

Node.prototype.nt = function() {
return this.nodeType;
}

Ari.

--
Elections only count as free and trials as fair if you can lose money
betting on the outcome.

解决方案


Ari Krupnik wrote:

scripts can add methods to the prototypes of builtin objects in
JaavScript. I can assign functions to String.prototype.*, for
instance. I want to add a method to Node, but when I try to execute
the following IE says "''Node'' is undefined." Mozilla works as I
expected it to.

Well, actually Mozilla works in - maybe convenient in some
circumstances - but non-expected way.
prototype is property of a JavaScript object; DOM Node is not a
JavaScript object and it has nothing to do with say Object()
constructor (same way as say DIV element has nothing to do with Array
;-)

IE exposes the base [element] interface via behavior mechanics. This
way you can make say each <pelement to have AJAX interface or each
<divacting as media player. But in case of Node I really don''t know
what to suggest as it is not an element in (X)HTML / XML sense, it is
unit one level below. Are you trying to uniformly augment every single
element on your page? What is your actual aim? (so maybe some solution
is possible).



Ari Krupnik wrote:

scripts can add methods to the prototypes of builtin objects in
JaavScript. I can assign functions to String.prototype.*, for
instance. I want to add a method to Node, but when I try to execute
the following IE says "''Node'' is undefined." Mozilla works as I
expected it to. Is Node called something else in IE? Does IE not allow
manipulating the prototypes of some builtin objects?

Node.prototype.nt = function() {
return this.nodeType;
}

There is a base object for the DOM that implements the Node interface,
in Gecko browsers it''s called "Node" and you can mess with the
prototype.

IE doesn''t have a Node object, though you can extend DOM objects to
some extend using behaviours:

<URL:
http://msdn.microsoft.com/library/de...o/creating.asp

>


--
Rob



"Ari Krupnik" <ar*@lib.aerowrote in message
news:86************@deb.lib.aero...

scripts can add methods to the prototypes of builtin objects in
JaavScript. I can assign functions to String.prototype.*, for
instance. I want to add a method to Node, but when I try to execute
the following IE says "''Node'' is undefined." Mozilla works as I
expected it to. Is Node called something else in IE? Does IE not allow
manipulating the prototypes of some builtin objects?

The Node is not a "built in object", it is a "host object" (or at least,
all objects implementing the Node interface in browser DOMs are host
objects), and host objects are not required to facilitate modification
of their prototypes, expose prototypes (even have prototypes) or expose
constructors.

As a result some hosts may provide those facilities (as Mozilla does)
and others may not (like IE). Both alternatives (and everything in
between) are completely in accordance with the javascript language
specification, and no other specifications (such as the W3C DOM, and its
ECMAScript bindings) has attempted to apply any additional constraints
on host objects in the web browser context.

Richard.


这篇关于内置对象原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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