Тёмный

javaScript Method chaining tutorial ( function chaining) 

techsith
Подписаться 147 тыс.
Просмотров 62 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 83   
@MyGeorge1964
@MyGeorge1964 7 лет назад
Note the shorthand instead of "{add: add, substract: substract, print: print};" you can now write return {add, substract, print}; And thanks for this clear demonstration.
@Techsithtube
@Techsithtube 7 лет назад
yes. thanks for pointing it out.
@injrav
@injrav 8 лет назад
very very good example . Not only method chaining the example at the end is very useful for writing a class with private fields and public methods..
@yasirkaram
@yasirkaram 5 лет назад
I have never found most precise, concise and trick catching instructive series on RU-vid or Udemy like this, really good baked pastry been brought only by "bakers". If you would author a book on JS it will be of most useful one
@angshu7589
@angshu7589 5 лет назад
The only video I understood.
@siu17
@siu17 5 лет назад
Great tutorial, but “substract”??
@shyamjaiswal5402
@shyamjaiswal5402 5 лет назад
x.add(3) is fine when we call it, why undefined ? inside the console.log?
@sayhongtan8993
@sayhongtan8993 8 лет назад
This is great! Illustrates Method Chaining clearly!
@anupsingh24
@anupsingh24 6 лет назад
Kamaal karte ho Patel ji
@KrishnaKamal49
@KrishnaKamal49 8 лет назад
This is very helpful, thanks for sharing your knowledge!
@jayaprakash456abc
@jayaprakash456abc 8 лет назад
Very helpful. I am newbie to java script. Thanks for the video.
@faisalnaseer798
@faisalnaseer798 7 лет назад
The best one
@Techsithtube
@Techsithtube 7 лет назад
I am glad it helped. Thanks for watching!
@kemmrthappy2804
@kemmrthappy2804 7 лет назад
i must very interesting tutorials , you simply made it so easy to understand ,thanks a lot
@ECUdweber
@ECUdweber 8 лет назад
Great video. FYI, it's "subtract".
@Techsithtube
@Techsithtube 8 лет назад
+ECUdweber Thanks for the correction you are the first one to notice. :)
@sanjayvns1987
@sanjayvns1987 2 года назад
What is difference in defining a variable like $url or var url in js
@compromisenonono8762
@compromisenonono8762 8 лет назад
it seems that the returned object is nothing but bunch of functions,these bunch of functions share the out parameter i,they can modify this i and return the object itself,which was cool, thanks sith!
@coolprashantmailbox
@coolprashantmailbox 8 лет назад
awesome sir..your advanced js tutorial
@VishnuPrasadmsvp
@VishnuPrasadmsvp 7 лет назад
Very nice explanation.. hurray👏👏
@krishnayadav2879
@krishnayadav2879 3 года назад
Anyone Here to know how Promise.then().catch() chained together ?
@Techsithtube
@Techsithtube 3 года назад
Promise returns an object with "then" method, then method returns an object with "catch" method.. :)
@karthikpanjaje7853
@karthikpanjaje7853 6 лет назад
Subtract*
@Techsithtube
@Techsithtube 6 лет назад
:)
@keronwilliams5392
@keronwilliams5392 3 года назад
Is it possible to chain methods from factory functions? E.g. sayName().location().favFoods(). I can't use the `return this` keyword inside the factory function like how you would with a regular constructor function :( const nerd = (user, city, food) => { const { sayName, location } = Person(user, city) const { favFoods } = FaveFood(food, user) // console.log(`${user} likes nerd stuff!`) return { sayName, location, favFoods, doSOmethingNerdy } return this }
@carloseduardogomezlozano491
@carloseduardogomezlozano491 4 года назад
one question, please is it correct to do the following code? var obj = function () { var oper = { i: 0, add: function (j) { this.i += j return this }, sub: function (j) { this.i -= j return this }, print: function () { console.log(this.i) }, } return oper } var x = obj() //no need new x.add(3).sub(2).print() //1 console.log(x) I hope your answer, thank you. Blessings
@creative-commons-videos
@creative-commons-videos 2 года назад
hi, how to limit method chain to some perticular function ? returning this will give all method access, and i am trying to make a routing package where i need to return a chain of method like router.get() here i only want to return get, post and other method but i have many methods in class that all are showing up, i also have applyMiddleware() method that i only want after method is selected but it is showing while accessing router.* anything
@sudiptasarkar4438
@sudiptasarkar4438 5 лет назад
What is the logic behind return this; after you made 'i' as private variable?
@MostwantedKamal
@MostwantedKamal 8 лет назад
thanks for a great tutorial..it completely makes sense for me ..
@deividas777
@deividas777 7 лет назад
Thanks great explanation, easy to follow
@reallybigbiscuit3568
@reallybigbiscuit3568 8 лет назад
This was extremely useful. Thank you for the straighforward and great tutorial. :D
@sudiptasarkar4438
@sudiptasarkar4438 5 лет назад
When you write this.i += i inside this.add func() why it isn't creating a new this? I thought only arrow func doesn't have their own this
@devope
@devope 6 лет назад
so, all this 2 examples are working, so I can use any of them?
@bboyjojo1988
@bboyjojo1988 6 лет назад
Nice lesson, thank you for teaching, keep up the good work, peace!
@SheshagiriPai
@SheshagiriPai 8 лет назад
I have always added new when creating the object. How did you get away with removing the new at 10:08 Can you please elaborate. Thanks :)
@Techsithtube
@Techsithtube 8 лет назад
+Sheshagiri Pai Thanks for watching the video . Following is the explanation you asked. var obj = function() { this.i = 1; this.geti = function(){ return this.i;}; }; the above behaves more like a class. so if i need to create an object from this class i can use 'new' like this var a = new obj(); var b = new obj(); var c = new obj(); as you can see i can create multiple object from this obj class function . Basically 'new' here means creating a new object. Now lets look at closure var obj = function() { var i = 1; var geti = function(){ return i;); return {geti:geti}; }; var a = obj(); here i when i do var a= obj(); , i am not creating a new object . obj() is actually returning me a object with function geti . you can see in this statement "return {geti:geti};" that is why i am not using new. also in the first example you dont see return statement. Thanks
@meriemkaroun7626
@meriemkaroun7626 8 лет назад
And it is always a function, isn't?! var obj = function(){ this.num = 0; };
@rahulmarne4112
@rahulmarne4112 7 лет назад
javaScript Method chaining tutorial ( function chaining) what you want to explain in this video did get it please tell me
@lycan2494
@lycan2494 5 лет назад
so function xpressions inside a function expression
@williamheckman4597
@williamheckman4597 5 лет назад
I just wish the keyboard clicks could be louder...
@rembrandt702
@rembrandt702 8 лет назад
You don't create a closure, you use a closure because closure is a feature of the language.
@SirusDas
@SirusDas 7 лет назад
Hi, I liked your tutorial. Is there other way than just return{add:add, substract:st...} and why didn't you use new obj()??? Could you please guide me :)
@Techsithtube
@Techsithtube 7 лет назад
when you run the function it's returning the object with mehtods with closures. which means this is not a function constructor. only function constructor uses new. I have a tutorial on that called "constructor" you can look at that. You can return like this jsfiddle.net/7dg1g3j8/ does that answer your question?
@SirusDas
@SirusDas 7 лет назад
Your quick response is highly appreciated. I really liked your example at jsfiddle.net/7dg1g3j8/ and something like this "const cal = () => {" is very new to me. It was a great learning. Thank you for sharing your knowledge. Have a great time ahead and keep publishing :)
@sunilkumar-tk3gu
@sunilkumar-tk3gu 6 лет назад
Return this is instant object, what is value hold by this element, it is difficult to understand
@Techsithtube
@Techsithtube 6 лет назад
'this' means the reference to the entire object.
@moolipit
@moolipit 8 лет назад
i dont understand how come you were able to get the correct result here 04:45 but when you chain them you had to return the object first ???
@nanaooinam6583
@nanaooinam6583 6 лет назад
Mooli Morano m
@vineetharkut4920
@vineetharkut4920 6 лет назад
Nice explanation sir.. I have one doubt is that what is difference between creating object with new and without new operator because which i know (if i am wrong then rectify me) that while creating an object with new operator they maintain there own data member & method then i tied with above example without using new operator i was thinking that may be they are referring to same address/reference Without Using new Operator var x = obj(); var y = obj(); console.log(x===y) // false x.add(3).substract(2).substract(2).print(); // -1 y.add(3).substract(2).print(); // 1 With Using new Operator var x = new obj(); var y = new obj(); console.log(x===y) // false x.add(3).substract(2).substract(2).print(); // -1 y.add(3).substract(2).print(); // 1 can you help me to clear my this doubt..Thanks
@Techsithtube
@Techsithtube 6 лет назад
What you are looking for is understanding of how to create objects diffrent ways. Here is one of my tutorial that explains that. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-xizFJHKHdHw.html
@samyever2be
@samyever2be 7 лет назад
Hi, I have tried in my localhost, but i didn't get any console output, please guide me
@Techsithtube
@Techsithtube 7 лет назад
which one did you try?
@mdshoaibAlamgcetts
@mdshoaibAlamgcetts 6 лет назад
when we should use 'new' keyword and should not , please help me to understand this
@Techsithtube
@Techsithtube 6 лет назад
new is a constructor pattern. Basically when you want to create objects from a constructor. If you are doing functional programming where you are returning functions with closures and such you are using with out new. You should watch my object oriented series to understand 'new' keyward . ru-vid.com/group/PL7pEw9n3GkoW0ceMeoycg9D00YjPAbtvt
@mdshoaibAlamgcetts
@mdshoaibAlamgcetts 6 лет назад
techsith thank you so much ....I have learned alot from your videos . Once again thanks for sharing playlist will go through all
@tanisha4568
@tanisha4568 8 лет назад
Hi, Thank you for the wonderful video. Can you please share your jsFiddle link here. Thanks,
@TubeFreak44
@TubeFreak44 3 года назад
Calling both variables "i" is kinda misleading.
@mysticfakir2029
@mysticfakir2029 3 года назад
Why not just write a class instead of an object that acts as a class? Why in good heavens does Javascript even give you the option to do this?
@Techsithtube
@Techsithtube 3 года назад
Classes are there in JS but not used as much. Frameworks like react are completely moving away from classes.
@vigoworkchannel1681
@vigoworkchannel1681 3 года назад
This man is the best teacher, RU-vid has been recommending the wrong people to me
@muhammadsafiullah8428
@muhammadsafiullah8428 5 лет назад
thanks for this tutorial.
@karthiknedunchezhiyan7935
@karthiknedunchezhiyan7935 7 лет назад
jillakidumma
@Techsithtube
@Techsithtube 7 лет назад
:)
@rapoliit
@rapoliit 2 года назад
Simply superb ☺️
@ritsk4338
@ritsk4338 5 лет назад
Method chaining on closure is bit tough to understand for me
@stevkoria
@stevkoria 7 лет назад
are bhai substract nahi, Subtract :-)
@hn031
@hn031 3 года назад
This is a topic that's been on my mind for some time now, I've read blogs about method chaining but never quite understand it. Watching this video now makes me understand it better. Thanks
@Techsithtube
@Techsithtube 3 года назад
Glad it was helpful! Thanks for watching!
@Owenimus
@Owenimus 5 лет назад
How can I do this asyncronously?
@Techsithtube
@Techsithtube 5 лет назад
You have to return a promise for it to execute asynchronously.
@Owenimus
@Owenimus 5 лет назад
techsith That would return the promise itself, not the class, therefore I wouldn't be able to chain it.
@bagoquarks
@bagoquarks 8 лет назад
Nicely done. A very good use of 12 minutes for beginning JS programmers.
@sandipdas-cm5yz
@sandipdas-cm5yz 7 лет назад
very nice
@Techsithtube
@Techsithtube 7 лет назад
Thanks for watching!
@webpocetnik7862
@webpocetnik7862 7 лет назад
You are very good at explaining things.
@doit4941
@doit4941 7 лет назад
why return "this" ?
@Techsithtube
@Techsithtube 7 лет назад
When you return this. you return refrence to yourself ( in this case the main function ) , this way now you can can call the methods defined in itself using dot notation . x.add().add();
@guimarquesini
@guimarquesini 7 лет назад
but in the 'add' method for example, returning 'this' there will return the main function itself, but I don't understand why it doesn't return the add function
@Techsithtube
@Techsithtube 7 лет назад
In this case you only have one function. what if you have many functions like "add" you dont want to return only one function . instead you should return "this" so you can chain any functions.
@nafeesahmed4942
@nafeesahmed4942 7 лет назад
very nice explanation.
@tzetrikoiand441
@tzetrikoiand441 8 лет назад
Very informative video!
@MrChubib0
@MrChubib0 7 лет назад
this guy is on point! great teacher
@mohammadadilalam7185
@mohammadadilalam7185 7 лет назад
really helpful, nice one
Далее
setTimeout and setInterval in JavaScript
12:55
Просмотров 34 тыс.
Help Me Celebrate! 😍🙏
00:35
Просмотров 17 млн
Офицер, я всё объясню
01:00
Просмотров 2,4 млн
Java Method Chaining Tutorial #85
8:43
Просмотров 42 тыс.
Javascript Method Chaining
11:20
Просмотров 7 тыс.
JavaScript Generators Tutorial
11:46
Просмотров 56 тыс.
javaScript call apply and bind
15:23
Просмотров 356 тыс.
Help Me Celebrate! 😍🙏
00:35
Просмотров 17 млн