agn*_*ter 10 javascript firebug google-chrome
我特别想到Chrome,虽然Firebug很有意思.我尝试过toString()和valueOf(),但似乎都没有使用过.有趣的是,如果我接受一个函数它将显示函数定义 - 但是如果我添加一个toString()方法它将显示null!
var a = function(){};
console.log(a); // output: function (){}
a.toString = function(){ return 'a'; };
console.log(a); // output: null
a.valueOf = function(){ return 'v'; };
console.log(a); // output: null
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我不知道有什么办法。最好的选择是toString()在要记录的对象上定义一个方法,然后直接或间接调用它:
var o = {};
o.toString = function() {
return "Three blind mice";
};
console.log("" + o);
console.log(o.toString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1638 次 |
| 最近记录: |