Window.location is an object. But when you execute location.toString(), it converts the object to the equivalent location.href.
location.toString()
location.href
My question is: how? Can I customize objects for similar behavior?
You can add a method toStringto your object that returns what you want. In this casehref
toString
href
eg:
var obj = { href:'', toString:function(){ return this.href; } }; obj.href = 'http://stackoverflow.com'; obj.toString();