I would like to know, how jQuery assign a value to this
. I tried as follow, but I am getting an error saying that Uncaught ReferenceError: Invalid left-hand side in assignment
.
let each = function(o, callback) {
let keys = Object.keys(o);
for (let i = 0; i < keys.length; i++) {
(function() {
this = o[keys[i]];
callback();
})();
}
}
In jQuery
$("p").each(function() {
console.log(this);
});