简直就是超级 [英] simply super

查看:68
本文介绍了简直就是超级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好清单。这是我的第一个消息,它没什么需要的,但是很好玩。我只想听听一些关于我认为是javascript使用的好奇心的想法。我已经看到很多人想要在

javascript中实现某种类似超级功能的东西,而且它通常会被用于更大的仿效工作

班。但是,如果你真的需要*那种类型的功能,为什么

不能这样:


//假设foo有自己的sayIt属性和sayIt物业在

其原型链

var backup = foo.sayIt;

删除foo.sayIt;

foo .sayIt(); //现在,代表链子

foo.sayIt = backup;


所以你可以看到它很容易使用javascript在属性委托/查找中构建了

来模拟超类功能。如果你想更容易使用这种模式,那么




foo.supe = function(prop){

var backup = this [prop];

删除这个[prop];

if(typeof this [prop] ==''function''){

var r = this [prop]();

} else {

var r = this [prop];

}

这[prop] =备份;

返回r;

};


foo.supe (''sayIt'');


所以有一个通用超类函数的例子。它是
并不包括参数传递,即使这完全有可能。

那么这不是获得类似超级功能的最简单方法吗?
如果有人有反馈,我很乐意听到。我希望我已经清楚了。


您还可以在以下位置查看更完整的代码示例:
http://highlight.tumblr.com/post/55510055/


*在我的

javascript编码中,我个人并不需要超级功能。显然,你现在也没有Crockdolf

在他的经典javascript教学卷的底部阅读:

我已经写了8年的JavaScript了,我从来没有发现需要使用超级功能的
。超级想法在经典模式中相当重要

,但在原型和功能模式中似乎没有必要。我现在看到我早期尝试将
支持JavaScript中的经典模型作为一个错误。

来自: http://javascript.crockford.com/inheritance.html


-

感谢您的阅读,

m

解决方案

10月29日,2:58 * pm,dylan m。奥斯汀" < mr.f ... @ gmail.comwrote:


Hello列表。这是我的第一个消息,它没什么需要的,但是很好玩。我只想听听一些关于我认为是javascript使用的好奇心的想法。我已经看到很多人想要在

javascript中实现某种类似超级功能的东西,而且它通常会被用于更大的仿效工作

班。但是,如果你真的需要*那种类型的功能,为什么

不能这样:



更大的努力在很大程度上是误入歧途的尝试制作JavaScript

像Java一样(或其他具有经典继承的语言

模式。)


>

//假设foo拥有自己的sayIt属性和

中的sayIt属性其原型链

var backup = foo.sayIt;

删除foo.sayIt;

foo.sayIt(); //现在,代表链子

foo.sayIt = backup;



Yikes。

https://developer.mozilla.org/En/Cor.../Function/Call


>

所以你可以看到,在属性委托/查找中使用javascript'的内置

很容易模拟超级功能。如果你想更容易使用这种模式,那么




foo.supe = function(prop){

* var backup = this [prop];

*删除这个[prop];

* if(typeof this [prop] ==''function''){<

* * var r = this [prop]();

*} else {

* * var r = this [prop];

*}

*这[prop] =备份;

*返回r;


};


foo.supe(''sayIt'');


所以有一个通用超类函数的例子。即使这完全有可能,它也不包括论证传递。



当然。


那么这不是获得类似超级功能的最简单方法吗? br />
如果有人有反馈,我很乐意听到。我希望我已经清楚了。



调用超级方法很容易。宾语。什么是

trickier在没有提到名称对象的情况下这样做。


>

你也可以请参阅以下代码的更完整的代码示例: http://highlight.tumblr。 com / post / 55510055 /

*在我的

javascript编码中,我个人并不需要超级功能。显然,你现在也没有Crockdolf

在他的经典javascript教学卷的底部阅读:

我已经写了8年的JavaScript了,我从来没有发现需要使用超级功能的
。超级想法在经典模式中相当重要

,但在原型和功能模式中似乎没有必要。我现在看到我早期尝试将
支持JavaScript中的经典模型作为一个错误。

来自: http://javascript.crockford.com/inheritance.html



太糟糕了,原型人群没有看到这个。你会在他们的一个博客的底部发布一个链接

吗?


Yikes。


>
https://developer.mozilla.org/En/Cor...ference/Global ...



当然,好的''来电。我很高兴你提到它但是使用它你已经有了b $ b来找到你自己的方式来引用你想要调用的函数。当你

也写道:


调用超级方法很容易。宾语。 *什么是

trickier正在这样做而没有提到名称对象。



因此,这正是临时移除本地财产

所实现的,你不必参考''超级''对象。


太糟糕了,原型人群还没看过这个。你会在他们的一个博客的底部发布一个链接

吗?



来自Crockford页面的报价?我不能确定他们没有读过它

除了我不熟悉人群或他们的博客。


< blockquote> 10月30日,1:11 * pm,dylan m。奥斯汀" < mr.f ... @ gmail.comwrote:


Yikes。

https://developer.mozilla.org/En/Cor...ference/Global ...



当然,不错的打电话。我很高兴你提到它但是使用它你已经有了b $ b来找到你自己的方式来引用你想要调用的函数。当你


也写道:


调用超级方法很容易。宾语。 *什么是

trickier正在这样做而没有提到名称对象。



因此,这正是临时移除当地财产

所实现的,你不必参考''超级对象。



以一种非常笨拙的方式。我不推荐这种方法。


Hello list. This is my first message and it''s nothing needful but
rather playful. I''d just like to hear some thoughts on something I
consider to be a curiosity of javascript usage. I''ve seen a lot of
folks looking to implement some kind of super-like functionality in
javascript and it''s usually baked into some larger effort of emulating
classes. However if you really need* that type of functionality why
not get it like so:

//assuming that foo has its own sayIt property and a sayIt property in
its prototype chain
var backup = foo.sayIt;
delete foo.sayIt;
foo.sayIt(); // now, delegates up the chain
foo.sayIt = backup;

So you can see that it''s easy enough to make use of javascript''s built-
in property delegation/lookup to emulate super-like functionality. And
if you wanted to make easier use of that pattern:

foo.supe = function( prop ){
var backup = this[prop];
delete this[prop];
if( typeof this[prop] == ''function'' ){
var r = this[prop]();
}else{
var r = this[prop];
}
this[prop] = backup;
return r;
};

foo.supe(''sayIt'');

So there''s an example of a general purpose super-like function. It
doesn''t include argument passing even though that''s entirely possible.
So is that not the simplest way of getting super-like functionality?
If anyone has some feedback I''d love to hear it. I hope I''ve been
clear.

You can also see a more complete working example of the code at:
http://highlight.tumblr.com/post/55510055/

* I haven''t personally needed super-like functionality in my
javascript coding. Apparently, neither has Crockdolf as you can now
read at the bottom of his scroll of classical javascript teachings:
"I have been writing JavaScript for 8 years now, and I have never once
found need to use an uber function. The super idea is fairly important
in the classical pattern, but it appears to be unnecessary in the
prototypal and functional patterns. I now see my early attempts to
support the classical model in JavaScript as a mistake."
from: http://javascript.crockford.com/inheritance.html

--
thanks for reading,
m

解决方案

On Oct 29, 2:58*pm, "dylan m. austin" <mr.f...@gmail.comwrote:

Hello list. This is my first message and it''s nothing needful but
rather playful. I''d just like to hear some thoughts on something I
consider to be a curiosity of javascript usage. I''ve seen a lot of
folks looking to implement some kind of super-like functionality in
javascript and it''s usually baked into some larger effort of emulating
classes. However if you really need* that type of functionality why
not get it like so:

The larger effort is largely a misguided attempt to make JavaScript
work like Java (or other languages with classical inheritance
patterns.)

>
//assuming that foo has its own sayIt property and a sayIt property in
its prototype chain
var backup = foo.sayIt;
delete foo.sayIt;
foo.sayIt(); // now, delegates up the chain
foo.sayIt = backup;

Yikes.

https://developer.mozilla.org/En/Cor.../Function/Call

>
So you can see that it''s easy enough to make use of javascript''s built-
in property delegation/lookup to emulate super-like functionality. And
if you wanted to make easier use of that pattern:

foo.supe = function( prop ){
* var backup = this[prop];
* delete this[prop];
* if( typeof this[prop] == ''function'' ){
* * var r = this[prop]();
* }else{
* * var r = this[prop];
* }
* this[prop] = backup;
* return r;

};

foo.supe(''sayIt'');

So there''s an example of a general purpose super-like function. It
doesn''t include argument passing even though that''s entirely possible.

Of course.

So is that not the simplest way of getting super-like functionality?
If anyone has some feedback I''d love to hear it. I hope I''ve been
clear.

It is easy enough to invoke a method of the "super" object. What is
trickier is doing it without mentioning the object by name.

>
You can also see a more complete working example of the code at:http://highlight.tumblr.com/post/55510055/

* I haven''t personally needed super-like functionality in my
javascript coding. Apparently, neither has Crockdolf as you can now
read at the bottom of his scroll of classical javascript teachings:
"I have been writing JavaScript for 8 years now, and I have never once
found need to use an uber function. The super idea is fairly important
in the classical pattern, but it appears to be unnecessary in the
prototypal and functional patterns. I now see my early attempts to
support the classical model in JavaScript as a mistake."
from:http://javascript.crockford.com/inheritance.html

Too bad the Prototype crowd hasn''t read this. Would you post a link
at the bottom of one of their blogs?


Yikes.

>
https://developer.mozilla.org/En/Cor...ference/Global...

Sure, good ol'' call. I''m glad you mention it but to use it you''ve got
to find your own way reference the function you want to call. As you
also wrote:

It is easy enough to invoke a method of the "super" object. *What is
trickier is doing it without mentioning the object by name.

So that''s exactly what temporary removal of the local property
achieves, you don''t have to reference the ''super'' object.

Too bad the Prototype crowd hasn''t read this. Would you post a link
at the bottom of one of their blogs?

The quote from Crockford''s page? I can''t be sure they haven''t read it
and besides I''m not familiar with the crowd or their blogs.


On Oct 30, 1:11*pm, "dylan m. austin" <mr.f...@gmail.comwrote:

Yikes.

https://developer.mozilla.org/En/Cor...ference/Global...


Sure, good ol'' call. I''m glad you mention it but to use it you''ve got
to find your own way reference the function you want to call. As you

also wrote:

It is easy enough to invoke a method of the "super" object. *What is
trickier is doing it without mentioning the object by name.


So that''s exactly what temporary removal of the local property
achieves, you don''t have to reference the ''super'' object.

In a very clumsy way. I wouldn''t recommend that method.


这篇关于简直就是超级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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