What is the Chainability?

Asked

Viewed 84 times

4

What exactly is Chainability ?

It is applicable in languages other than Javascript ?

I researched a little, but the term washes me for unrelated articles, I believe that does not leave what exactly seek to understand such a concept.

  • 1

    Possible duplicate: https://answall.com/q/56168/129

1 answer

3


The term "Chainability" comes from English "chain", meaning "chain" (not "chain" of prison) or "chain". Therefore, the term means "ability to create chains".

Chainability is the ability, within the programming language, of an object to create chains (or chaining) derived from himself.

JQuery’s good at that:

$("#id")
.filter(".clickme")
.click(function(){
   alert("You are now leaving the site.");
})
.end()
.filter(".hideme")
.click(function(){
  $(this).hide();
  return false;
})
.end();

See the various chains created for the same element #id.

In pure Javascript, an example of chaining would get values from a single function:

var Kitten = function() {
  this.name = 'Garfield';
  this.color = 'brown';
  this.gender = 'male';
};

var bob = new Kitten();

console.log(bob.name); // retorna "Garfield"
console.log(bob.color); // retorna "brown"

In short, the concept of "chaining" is when a single object provides multiple values, instances, or functions. The advantage of this is that you can get multiple results without having to repeat codes.

It is applicable in languages other than Javascript?

This question can be answered by connoisseurs of languages other than Javascript, since not everyone dominates all programming languages. But I believe that many other advanced languages may have the same ability.

Research source:

  • Thank you very much, I had seen something similar only not with so many strings in Python : Gui ().run () ... ( In this case the Object ' Gui ' is not assigned to anything, but is simply executed )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.