问题描述
|
window.location是一个对象。但是,当您执行
location.toString()
时,会将对象转换为等效于location.href
的对象。
我的问题是?我可以将对象设置为类似的行为吗?
解决方法
您可以向对象添加
toString
方法,该方法返回所需的内容。在这种情况下href
例如:
var obj = {
href:\'\',toString:function(){
return this.href;
}
};
obj.href = \'http://stackoverflow.com\';
obj.toString();