我尝试覆盖toString()函数,但发现重写的函数根本没有被调用。
我的尝试:
DIRECTION = {
NONE : 0,
DIAGONAL: 1,
UP: 2,
LEFT: 3
};
var Node = function () {
this.direction = DIRECTION.NONE;
this.weight = 0;
};
Node.prototype.toString = function NodeToSting(){
console.log('Is called');
var ret = "this.weight";
return ret;
};
(function driver(){
var node1 = new Node();
console.log(node1);
//findLcs("ABCBDAB", "BDCABA");
})();
输出:
{ direction: 0, weight: 0 }
console.log
不会输出。 - elclanrs