Я попытался переопределить toString(), но я обнаружил, что переопределенная функция не вызвана вообще.Почему overriden toString() не вызывается в javascript
Я прошел через this и this, но я не могу отслеживать свою ошибку.
Моя попытка:
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
Где вызов toString? – Jonathan