Every object in JavaScript inherits a valueOf() method from Object.prototype. But when we say obj.valueOf(), what exactly do we mean, the value of an object?
Tag Archives: JavaScript
Difference: arr.join, arr.toString, arr.toLocaleString
There are multiple ways to churn out a string version of a variable. Take Arrays for example, there are 3: join, toString, toLocaleString.
But what’s the difference?
Non-enumerable Properties
I was trying to figure out a way to enumerate through properties of Math object when I realise that I can’t access any. Whaaat? Why?
Object.prototype.toString.call()?
This seems to be a standardised way to tell the type of a javascript object. Why?
jQuery: Difference between bind, live and on
Equivalent:
$('button').bind('click', fn);
$('button').on('click', fn);
Equivalent:
$('button').live('click', fn);
$(document.body).on('click', 'button', fn);
jQuery: keyup, keydown, keypress?
In normal cases, go for keyup:
$(document).keyup(function(e){
console.log(e.which);
});
Reasons:
keydownkeeps firing when user holds the keys down, whilekeypressandkeyupfire only once.keypressdoesn’t detect special keys (e.g.SHIFT),keydownandkeyupdo.
Requiring JavaScript & Stylesheets with Requirejs & Sprockets
Demo for requiring JavaScript and Stylesheets in Ruby on Rails: