jQuery方法是否是流畅编程的一个例子? [英] Is jQuery method chaining an example of fluent programming?

查看:99
本文介绍了jQuery方法是否是流畅编程的一个例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JavaScript / jQuery有点新鲜,但是当我看到方法链接的例子时,它立刻让我感到很熟悉。 LINQ等其他接口也做类似的事情,其中​​一组方法的返回类型与它们运行的​​类型相同(TweetSharp做了非常相似的事情)。这是流畅编程的一个例子吗?我读到的关于jQuery的大部分内容都说其他库已经借用了这种方法链接的想法 - 这个想法是否源于jQuery?

I'm somewhat new to JavaScript/jQuery, but when I saw examples of method chaining it struck me as instantly familiar. Other interfaces like LINQ do something similar where the return type of a set of methods is the same as the type they operate on (TweetSharp does something very similar). Is this an example of fluent programming? Much of what I read about jQuery says that other libraries have "borrowed" this idea of method chaining - did the idea originate with jQuery?

推荐答案

jQuery确实严重遵循构建器模式 / 流畅的界面,但它肯定不是整个设计模式的先驱。其他库可能在jQuery之后跟随并借用了它的方法。这只是jQuery的成名,它使它看起来像是用jQuery创建的。

jQuery indeed heavily follows the builder pattern / fluent interface, but it is certainly not the pioneer of the design pattern at whole own. The other libraries likely followed after jQuery and borrowed its approach. It's just the fame jQuery has made which make it look like to originate with jQuery.

这篇关于jQuery方法是否是流畅编程的一个例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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