Creating a working $(foo).find() method
Hi, thanks for creating ki.js!
There are two usecases of the constructor that seem to not work so well.
I'm trying to implement a simple find() method but I cannot get it to work correctly. I think this might be because the constructor does something vonky, with NodeList objects, but I'm not sure.
Here's my implementation: ``js` $.prototype.find = function (selector) { var res = [] this.each(function (element) { res = res.concat(new $(element.querySelectorAll(selector))) }) return res }
There are several issues with the above code - the array needs to be flattened across multiple calls to `querySelectorAll` amongst other things.
What I am wondering is if it is possible to implement this method as an extension or if I need access to the internal c variable and thus the method must be within the main ki.js code.
Also, there are two common usecases that I find missing from the constructor which are `$(Element)` - I.e. creating a $ object wrapping an existing element and `$([Element])` which would solve part of the prolem with implementing the find method above.
Last but not the least, I'm wondering about the e variable in the i function:
```js
/*
* init function (internal use)
* a = selector, dom element or function
*/
function i(a) {
c.push.apply(this, a && a.nodeType ? [a] : '' + a === a ? b.querySelectorAll(a) : e)
}
/*
* $ main function
* a = css selector, dom object, or function
* http://www.dustindiaz.com/smallest-domready-ever
* returns instance or executes function on ready
*/
$ = function (a) {
return /^f/.test(typeof a) ? /c/.test(b.readyState) ? a() : $(b).on('DOMContentLoaded', a) : new i(a)
}
Is the e correct here? What is the expected value of e?
Kind regards, Tarjei
hi @tarjei could this be solved by https://github.com/dciccale/ki.js/pull/24 ?
I haven't tested it, but it might :)
This will work when #24 is merged, after a bug is fixed.