Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
On the bind example, heads up that in some older browsers you need to pass console as the first argument to any console.<method>.bind(). Not that this is a particularly real-world thing to do, but it's bitten me a few times when trying to debug a promise chain in an older browser; I always love to do promise.then(console.log), but in old browsers this breaks until you do promise.then(console.log.bind(console)).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
for(let i=0; i<10; i++) {
setTimeout(()=>console.log(i),i*500);
};
for(var i=0; i<10;i++) {
setTimeout(console.log.bind(null,i), i*100);
};
for(var i=0; i<10; i++) {
(function(x){
setTimeout(()=> console.log(x), x*100)
})(i);
};
On the
bind
example, heads up that in some older browsers you need to passconsole
as the first argument to anyconsole.<method>.bind()
. Not that this is a particularly real-world thing to do, but it's bitten me a few times when trying to debug a promise chain in an older browser; I always love to dopromise.then(console.log)
, but in old browsers this breaks until you dopromise.then(console.log.bind(console))
.