Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should ToArray() and Each() not provide JQuery objects? #15

Open
flimzy opened this issue Jul 4, 2016 · 4 comments
Open

Should ToArray() and Each() not provide JQuery objects? #15

flimzy opened this issue Jul 4, 2016 · 4 comments

Comments

@flimzy
Copy link
Member

flimzy commented Jul 4, 2016

There may be other such instances, but at least the two functions ToArray() and Each() iterate over elements of a jQuery object, exposing each element as another jQuery object in turn. However, the current implementation exposes them as interface{}s, which must then be coerced back into jquery.JQuery objects. Wouldn't it be more natural to just expose these directly? Would this ever be incorrect? Specifically, change the functions to have these signatures:

func (j JQuery) ToArray() []JQuery

func (j JQuery) Each(fn func(int, JQuery)) JQuery
@rusco
Copy link
Member

rusco commented Jul 6, 2016

you say: "iterate over elements of a jQuery object".
In this example its an array of plain dom elements:

https://jsfiddle.net/m31rxf76/1/

@flimzy
Copy link
Member Author

flimzy commented Jul 6, 2016

I'm not exactly sure what distinction you're making, @rusco. Probably I spoke unclearly.

In straight jQuery, toArray() returns an array of jQuery objects. I'm suggesting we honor that behavior here, and return []JQuery rather than returning []interface{}. Beneath, both are the same--both represent JQuery objects. It's just a matter of not having to convert []interface{} back to []JQuery manually.

@rusco
Copy link
Member

rusco commented Jul 6, 2016

I am just questioning the assumptions you make: "... returns an array of jQuery objects". I think it's an array of plain (untyped) objects.

The typescript definition files say it's "any[]" in case of toArray and an "element" as an argument for each:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/jquery/jquery.d.ts#L2784

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/jquery/jquery.d.ts#L2830

@flimzy
Copy link
Member Author

flimzy commented Jul 6, 2016

OIC. Yes, you're right: https://jsfiddle.net/hgnxmqk8/

In that case, I suggest rather returning []*js.Object for ToArray().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants