MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2d5fw/ancienttools/p6sfy06
r/ProgrammerHumor • u/soap94 • 2d ago
387 comments sorted by
View all comments
Show parent comments
7
Can't chain methods in vanilla JS
1 u/Agfa100asa 2d ago ??? 1 u/shadowspock 1d ago In jQuery you can chain methods like this: $('#id').addClass('red').prop('hidden', false).val('warning').attr('data-something', 1234); Can't do that in vanilla JS. 1 u/Agfa100asa 1d ago yes you can. const personne = { nom: "Alice", direBonjour() { console.log(`Bonjour ${this.nom}`); return this; }, direAuRevoir() { console.log(`Au revoir ${this.nom}`); return this; } }; personne .direBonjour() .direAuRevoir();
1
???
1 u/shadowspock 1d ago In jQuery you can chain methods like this: $('#id').addClass('red').prop('hidden', false).val('warning').attr('data-something', 1234); Can't do that in vanilla JS. 1 u/Agfa100asa 1d ago yes you can. const personne = { nom: "Alice", direBonjour() { console.log(`Bonjour ${this.nom}`); return this; }, direAuRevoir() { console.log(`Au revoir ${this.nom}`); return this; } }; personne .direBonjour() .direAuRevoir();
In jQuery you can chain methods like this:
$('#id').addClass('red').prop('hidden', false).val('warning').attr('data-something', 1234);
Can't do that in vanilla JS.
1 u/Agfa100asa 1d ago yes you can. const personne = { nom: "Alice", direBonjour() { console.log(`Bonjour ${this.nom}`); return this; }, direAuRevoir() { console.log(`Au revoir ${this.nom}`); return this; } }; personne .direBonjour() .direAuRevoir();
yes you can. const personne = { nom: "Alice",
direBonjour() { console.log(`Bonjour ${this.nom}`); return this; },
direAuRevoir() { console.log(`Au revoir ${this.nom}`); return this; } };
personne .direBonjour() .direAuRevoir();
7
u/shadowspock 2d ago
Can't chain methods in vanilla JS