R
R
RocketFloor2017-10-28 16:38:08
JavaScript
RocketFloor, 2017-10-28 16:38:08

How to make your own jQuery from scratch?

How to call methods on a function in any order?
$(".class").parent().children().next().prev().hide().show() and so on.
I looked at jQuery sources and did not understand. I want to create my own library similar to jQuery for learning purposes. Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2017-10-28
@RocketFloor

Each method must return a reference to your object
jsfiddle.net/96sa9d7e

D
Decadal, 2017-10-28
@Decadal

How to call methods on a function in any order?

you mean in any order? order matters.
To call functions cascaded, you need to return return this in each function;

D
Denis Bukreev, 2017-10-28
@denisbookreev

In each function, return an object.
Those. calling , takes an object and returns it at the end of the function, thus taking the return into an object, working with it, and returning it too, so that the next method down the chain can work further. In the case of , etc., return the parent or child respectively $('.class').hide().show()hide()$('.class')show()hide()
parent()children()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question