拦截实例 [英] Intercept instanceof

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

问题描述




是否可以拦截对instanceof的调用?并返回一些东西

不同?我想看看是否有可能实现像多继承一样的事情,特别是使用instanceof,其中一个

组件扩展了一个对象并实现了一些监听器接口

用于MVC架构。

Hi,

Is it possible to intercept a call to "instanceof" and return something
different? I wanted to see if it was possible to implement something
like multiple inheritance, especially to use instanceof where a
component extends an object and implements some listener interface too
for a MVC architecture.

推荐答案

1月21日,7:51 * am,Robert< rob。 .. @ nowhere.xwrote:
On Jan 21, 7:51*am, Robert <rob...@nowhere.xwrote:




是否可以拦截对instanceof的调用?并返回一些东西

不同?我想看看是否有可能实现一些东西
Hi,

Is it possible to intercept a call to "instanceof" and return something
different? I wanted to see if it was possible to implement something



No.

No.


喜欢多重继承,特别是使用instanceof

组件扩展一个对象并为MVC架构实现一些监听器接口


like multiple inheritance, especially to use instanceof where a
component extends an object and implements some listener interface too
for a MVC architecture.


Jeremy J Starcher写道:
Jeremy J Starcher wrote:

2008年1月21日星期一13:51: 22 +0100,Robert写道:
On Mon, 21 Jan 2008 13:51:22 +0100, Robert wrote:

>是否可以拦截对instanceof的调用?并返回一些不同的东西?我想看看是否有可能实现像多继承一样的东西,尤其是使用instanceof,其中
组件扩展了一个对象,并为MVC架构实现了一些监听器接口。
>Is it possible to intercept a call to "instanceof" and return something
different? I wanted to see if it was possible to implement something
like multiple inheritance, especially to use instanceof where a
component extends an object and implements some listener interface too
for a MVC architecture.



Javascript没有OOP,因为它存在于其他语言中,你

可能需要重新考虑你的目标。


Javascript does not have OOP as it exists in other languages, you
may need to re-think your goal.



Utter废话。

http://javascript.crockford.com/javascript.html
http://en.wikipedia.org/wiki/Prototy...ed_programming


请保持你的机智自己的例子。

PointedEars

-

现实主义:HTML 4.01严格

福音:XHTML 1.0 Strict

疯狂:XHTML 1.1作为应用程序/ xhtml + xml

- Bjoern Hoehrmann

Utter nonsense.

http://javascript.crockford.com/javascript.html
http://en.wikipedia.org/wiki/Prototy...ed_programming

Please also keep your half-witted examples to yourself.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


托马斯''PointedEars'' Lahn写道:
Thomas ''PointedEars'' Lahn wrote:

Jeremy J Starcher写道:
Jeremy J Starcher wrote:

> 2008年1月21日星期一13: 51:22 +0100,Robert写道:
>On Mon, 21 Jan 2008 13:51:22 +0100, Robert wrote:

>>是否可以拦截对in的调用stanceof"返回不同的东西?我想看看是否有可能实现像多继承一样的东西,尤其是使用instanceof
组件扩展对象并实现一些监听器接口
用于MVC架构。
>>Is it possible to intercept a call to "instanceof" and return something
different?I wanted to see if it was possible to implement something
like multiple inheritance, especially to use instanceof where a
component extends an object and implements some listener interface too
for a MVC architecture.


http:// javascript.crockford.com/javascript.html
http ://en.wikipedia.org/wiki/Prototy...ed_programming



我当然看到过你最受欢迎的例子:)


无论如何,我想出了一个合理的方法来实现它。我不能使用

instanceof,但也不算太糟糕。


我现在会做这样的事......


函数IMyListener()

{

}


IMyListener.prototype.event = function() {};

IMyListener .__ INTERFACE = true;


当我验证参数并期待一个接口时我称之为

isImplementation检查参数对象是否实现了接口的所有方法。


我仍​​然不能使用instanceof,这太糟糕了,但直到现在我只需要

它就可以进行参数验证。

I have seen your popular examples before of course :)

Anyway, I figured a reasonable way to implement it. I can''t use
instanceof, but it is not too bad.

I will do something like this now...

function IMyListener()
{
}

IMyListener.prototype.event = function() {};
IMyListener.__INTERFACE = true;

And when I validate arguments and expect an interface I call an
isImplementation that checks whether the argument object implements all
the methods of an interface.

I still can''t use instanceof, which is too bad, but till now I just need
it for arguments validation anyway.


这篇关于拦截实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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