简直就是超级

扫码查看
如果有人有反馈,我很乐意听到。我希望我已经清楚了。 您还可以在以下位置查看更完整的代码示例: 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页面的报价?我不能确定他们没有读过它 除了我不熟悉人群或他们的博客。 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 butrather playful. I''d just like to hear some thoughts on something Iconsider to be a curiosity of javascript usage. I''ve seen a lot offolks looking to implement some kind of super-like functionality injavascript and it''s usually baked into some larger effort of emulatingclasses. However if you really need* that type of functionality whynot get it like so://assuming that foo has its own sayIt property and a sayIt property inits prototype chainvar backup = foo.sayIt;delete foo.sayIt;foo.sayIt(); // now, delegates up the chainfoo.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. Andif 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. Itdoesn''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 beenclear.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 myjavascript coding. Apparently, neither has Crockdolf as you can nowread at the bottom of his scroll of classical javascript teachings:"I have been writing JavaScript for 8 years now, and I have never oncefound need to use an uber function. The super idea is fairly importantin the classical pattern, but it appears to be unnecessary in theprototypal and functional patterns. I now see my early attempts tosupport 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 butrather playful. I''d just like to hear some thoughts on something Iconsider to be a curiosity of javascript usage. I''ve seen a lot offolks looking to implement some kind of super-like functionality injavascript and it''s usually baked into some larger effort of emulatingclasses. However if you really need* that type of functionality whynot get it like so:The larger effort is largely a misguided attempt to make JavaScriptwork like Java (or other languages with classical inheritancepatterns.)>//assuming that foo has its own sayIt property and a sayIt property inits prototype chainvar backup = foo.sayIt;delete foo.sayIt;foo.sayIt(); // now, delegates up the chainfoo.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. Andif 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. Itdoesn''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 beenclear.It is easy enough to invoke a method of the "super" object. What istrickier 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 myjavascript coding. Apparently, neither has Crockdolf as you can nowread at the bottom of his scroll of classical javascript teachings:"I have been writing JavaScript for 8 years now, and I have never oncefound need to use an uber function. The super idea is fairly importantin the classical pattern, but it appears to be unnecessary in theprototypal and functional patterns. I now see my early attempts tosupport the classical model in JavaScript as a mistake."from:http://javascript.crockford.com/inheritance.htmlToo bad the Prototype crowd hasn''t read this. Would you post a linkat 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 gotto find your own way reference the function you want to call. As youalso wrote:It is easy enough to invoke a method of the "super" object. *What istrickier is doing it without mentioning the object by name.So that''s exactly what temporary removal of the local propertyachieves, you don''t have to reference the ''super'' object.Too bad the Prototype crowd hasn''t read this. Would you post a linkat the bottom of one of their blogs?The quote from Crockford''s page? I can''t be sure they haven''t read itand 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 gotto find your own way reference the function you want to call. As youalso 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 propertyachieves, you don''t have to reference the ''super'' object.In a very clumsy way. I wouldn''t recommend that method. 这篇关于简直就是超级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 22:10
查看更多