We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
var arr=[{a:1},{a:2}] $.map(arr, function(){console.log(this)})
Always print window, window
window, window
While as
var arr=[{a:1},{a:2}] $.each(arr, function(){console.log(this)})
Print right output: {a:1}, {a:2}
{a:1}, {a:2}
The text was updated successfully, but these errors were encountered:
@futurist
I think $.map() is designed to work in this way intentionally.
The source code is shown as follows:
// $.each() value = callback.call(elements[i], i, elements[i]); // $.map() value = callback(elements[i], i);
They are designed in a similar fashion as JQuery and the source code of JQuery is shown as follows:
// $.each() value = callback.call( obj[ i ], i, obj[ i ] ) // $.map() value = callback( elems[ i ], i, arg )
JQuery has mentioned that $.map() refers to the global (window) object and $.each() refers to an Object even if it is a simple string or number value.
$.map()
$.each()
Object
Sorry, something went wrong.
No branches or pull requests
Always print
window, window
While as
Print right output:
{a:1}, {a:2}
The text was updated successfully, but these errors were encountered: