开发者

Why does location.toString() report the same as location.href?

The window.location is an object. But when you execute location.toString开发者_C百科() it converts the object to the equivalent to location.href.

My question is how? And can I set up objects to a similar behaviour?


You can add a toString method to your object that returns what you want. In that case href

eg:

var obj = {
  href:'',
  toString:function(){
    return this.href;
  }
};

obj.href = 'http://stackoverflow.com';
obj.toString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜