several.5 Populate object with DOM node records based on params and go back target

several.5 Populate object with DOM node records based on params and go back target

several.5 Populate object with DOM node records based on params and go back target

The brand new params parameter introduced so you can dom(), then on to the getOrMakeDom() varies in the sort of factor that is certainly passed. Just like jQuery the new type’s away from value’s passed are people one of many after the:

The result of passageway params is the construction off a chain-in a position target that has had sources to nodes (age

  • css selector string (e.g. dom(‘body’))
  • html string (e.g. dom(‘

    Hellow

    Community!

    ‘))

  • Function node (e.grams. dom(document.body))
  • selection of element nodes (e.g. dom([file.body]))
  • an excellent NodeList (e.grams. dom(document.muscles.children))
  • a great HTMLcollection (elizabeth.g. dom(document.all))
  • a dom() target by itself. (elizabeth.grams. dom(dom()))

g. ) either in the DOM or in a document fragment. Lets examine how each of the above parameters can be used to produce an object containing node references.

The fresh reasoning permitting for example a multitude of factor items try found below throughout the code and you will starts with an easy examine to verify one params isn’t vague, a blank sequence, otherwise a sequence that have blank places. Should this be the fact we put a length possessions having a value of 0 on target made out of contacting GetOrMakeDOM and come back the thing so that the execution of your function stops. In the event the params isn’t an untrue (or false such as) well worth the newest performance of your mode goes on.

Next the params value, if a string, is checked to see if contains HTML. If the string contains HTML then a document fragment is created and the string is used as the innerHTML value for a

contained in the document fragment so that the string is converted to a DOM structure. With the html string converted to a node tree, the structure is looped over accessing top level nodes, and references to these nodes are passed to the object being created by GetOrMakeDom. If the string does not contain HTML execution of the function continues.

In the event the the a set selector, a good node list is generated from the getting in touch with this new queryselectorAll() means on the currentContext. If it’s just not a set selector i loop across the html collection, node number, number, otherwise target deteriorating the brand new node references and utilizing brand new recommendations since the philosophy within the target delivered back of contacting the brand new GetOrMakeDom.

All of this reason inside of GetOrMakeDom() function is somewhat challenging just realize that the idea of the constructor function should be to create an object which has had references to help you nodes (elizabeth.g. ) and you may productivity it target to help you dom().

a dozen.6 Perform for each() method and then make it an excellent chainable method

Whenever we invoke dom() we can availableness some thing connected to dom.fn thanks to prototypical genetics. (elizabeth.g. dom().each()). Not in place of jQuery tips attached to dom.fn run using the thing made out of the latest want Bisexual dating GetOrMakeDom constructor function. The brand new password less than configurations brand new each() means.

Because you you will expect the new for every single() strategy takes an effective callback function as the a parameter and you will invokes the brand new means (function the fresh new which worth into feature node object that have label()) per node element in the fresh getOrMakeDom target such. The new this worthy of inside of the for every() form try a mention of the getOrMakeDom target eg (elizabeth.grams. ).

Whenever a method will not return a regard (elizabeth.grams. dom().size returns a point) its potential so that method chaning by just going back the thing the procedure belongs also in the place of a specific worthy of. Fundamentally, we’re going back the fresh new GetOrMakeDom object so other method might be entitled about exemplory case of the object. Regarding the code less than I would like the newest for every single() method to end up being chainable, meaning even more actions are going to be titled immediately after calling per(), and so i just get back which. This new that it about code less than ‘s the object eg written of calling the new getOrMakeDom form.

No Comments

Post A Comment