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

forEachChild improvements #3

Open
killmenot opened this issue Sep 5, 2017 · 3 comments
Open

forEachChild improvements #3

killmenot opened this issue Sep 5, 2017 · 3 comments

Comments

@killmenot
Copy link
Contributor

if (callback) quit = callback.call(this, result, gnode);

  • pass index after gnode
  • accept thisArg to forEachChild method like Array.forEach does
@killmenot
Copy link
Contributor Author

Same can be applied for forEachLeafNode

@robtweed
Copy link
Owner

robtweed commented Sep 7, 2017

I don't think there's a real use case for either suggestion. forEachChild is iterating through the subscript values at a particular level of subscripting within a Global - the only 2 relevant values you need are the next subscript value and its corresponding DocumentNode, from which you can derive any other information.

@killmenot
Copy link
Contributor Author

The simple use case for index can be printing number of item without i variable declaration. I'm sure there are other cases that can be.

before:

var index = 0;

myDoc.forEachChild(function (nodeName, node) {
  console.log(`{index}: {nodeName}`)
  index++;
})

after

myDoc.forEachChild(function (nodeName, node, index) {
  console.log(`{index}: {nodeName}`)
})

thisArg is not common used case. I think we can skip it.

@killmenot killmenot reopened this Sep 7, 2017
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