Extend

3 minutes
Share the link to this page
Copied
  Completed
Merge the contents of an object onto the jQuery prototype to provide new jQuery instance methods.

Transcript

Hello, in this jQuery video, I am going to show you the extend method. The extend method allows you to merge the contents of two or more objects into the first object. So, really simple, what I've already done is created two objects, they can be as simple as done or as complex as you want, when you've got one of these object one, object two, and these have some properties, and this line here has no two extra properties of the Nona has weight and price. I didn't see it either conflicting, or the same property applied here as well for price. So to use the extend method, it's really simple. To do dollar extent.

You can only do this when some sort of event is triggered, maybe a button click, but the code is the same. And you just capsulated within that, you know, set event and open bracket method. You specified the two objects. Object one Okay, so this is the important part, this order matters because the second object I provided will be merged into the first one. So let me show you what happens. So if I were to console dot log, and if I console log object one, then I console log objects.

I'm going to do that thing afterwards as well save it, reload. Let's see what we get. So these are the first two console logs prior to the x, the extend method being called and he says got Apple banana. Let's open them up. So Nana price 204 done This right should enter now. And then if we go to the Yes, that's right.

Okay, and so so I forgot the next one. As you can see, it's merged into one. So this price has been, if we go to here, the price is now 200. It's also got the taste property as well. So that's just something to bear in mind, it will combine them. So you want the first one to be the one that's going to be overridden.

The second one will be unchanged, the first one will get modified. So that's it on how to use the extend method in jQuery. If you have any more questions, feel free to drop me a message as usual. I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.