Both jQuery and MathBox have query functions ($()
and select()
) which return objects with methods attached which act on all queried entities. E.g. $().addClass()
.
Does this pattern have a name?
The API-first design means that the software development team builds it ahead of the rest of an application. For example, the team designs API using GraphQL and Schema Definition Language (SDL). This definition becomes a single source of truth. Based on that, engineers generate fragments of application.
They should be reliable, accessible, and usable by anyone, anytime. By starting with API design, you can make sure that everything looks and works as intended. It’s especially important for FinTech APIs, where the level of product complexity and third-party integration can be pretty high.
Application programming interface delivers in spades. The APIs used in the API-first design, fall into three categories: The first kind is used for the purpose of simply building application. The second one is used for orchestration, composable APIs, and microservices.
Adapter pattern will have the same method name. X.DoSomething () will do different thing when it applies to different object. Façade pattern accesses different functions in separate different classes. Example of façade class should be when you want to create a validator class.
I've always heard jQuery API style being called "Fluent API", or as Wikipedia says: "Fluent Interface".
Check https://en.wikipedia.org/wiki/Fluent_interface#JavaScript
However, it's mainly about chaining methods, usually to build queries or transformation chains. What the methods do and how they act on the handled entities depends on the application domain.
For the case of jQuery, it's similar to a composite pattern: an action can be applied on a single entity or a collection of them transparently, using the same interface. The difference with the classic Composite design pattern is that we're not talking about pure OOP, but about something closer to functional programming where returned values always forward the API, though with a new state.
Check https://en.wikipedia.org/wiki/Composite_pattern
It's called a Higher Order function.
A Higher Order Function is any function that returns a function when executed, takes a function as one or more of its arguments, or both. If you have used any of the Array methods like map or filter, or passed a callback function to jQuery’s $.get, you have already worked with Higher Order Functions.
ref
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With