-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Chain
Mark Nadal edited this page Sep 16, 2018
·
1 revision
If you are unfamiliar with chaining, it is an API style that allows you to zoom into a context without having to create new variables. So rather than doing...
// ugly
var page = document.getElementById("page");
var child = page.firstElementChild;
child.style.background = "blue";
child.style.color = "green";
child.addEventListener('click', function(event){
console.log("hello world!");
}, true);
...you can just do
$('#page')
.children()
.first()
.css("background", "blue")
.css("color", "green")
.on("click", function(event){
console.log("hello world");
});
As you can tell, it was popularized by jQuery.
- You should also be familiar with how GUN improves upon this with reactive programming.
- You might be curious how the internal javascript implementation was built.