Skip to content

Conversation

@tiptronic
Copy link
Contributor

@tiptronic tiptronic commented Apr 29, 2020

Using dataSource[dataKey] has 2 issues:

  1. It searches the complete prototype chain (which is unefficient)
  2. If the resolved value is 0 or false the result is false (which isn't intended)

Example:
dataKey is 'id', it's value is zero:
e.g.
{
id: 0
}

So better to be explicit here, e.g. 👍
if(dataSource.hasOwnProperty(dataKey))

What kind of this PR? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Build-related changes
  • Other, please describe:

Other information:

Using `dataSource[dataKey]` has 2 issues:
1. It searches the complete prototype chain (which is unefficient)
2. If the resolved value is `0` or `false` the result is `false` (which isn't intended)

Example:
dataKey is 'id', it's value is zero:
e.g.
{
   id: 0
}

So better to be explicit here, e.g. 👍 
` if(dataSource.hasOwnProperty(dataKey)) `
@tangbc
Copy link
Owner

tangbc commented Apr 29, 2020

Good suggestion, but you need fix eslint error.

@tiptronic
Copy link
Contributor Author

just fixed the linting error

@tangbc tangbc merged commit 47d68f5 into tangbc:master Apr 30, 2020
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

Successfully merging this pull request may close these issues.

2 participants