A
A
Adel Khalitov2019-04-04 17:57:43
Angular
Adel Khalitov, 2019-04-04 17:57:43

Typescript mysticism or why is this nonsense happening?

I do the calculation using 30 functions.
I want to debug it at a certain step, but on any of the functions in the chain of sequences I get the same result.
Conditional example:

firstFunc(Parabola): object {
var sum = Parabola.a+Parabola.b;
var obj = {a: sum}
console.log(obj)
return obj;
}

secondFunc(Parabola):object {
var firstResult = this.firsnFunc(Parabola);
firstResult['newElement'] = 1;
}
final(Parabola) {
return this.secondFunc(Parabola);
}
final(Parabola);

And in the console we get:
Conditionally
{a: 2, newElement: 1}
a = 2 is conditional. The point is that I can't figure out why it also prints "newElement: 1" in the console, because it's done before the second function is called.
I am sure that I do not have the correct function design. Please advise how to fix this. I can’t post the original, because you can break your leg there!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-04
@SaveLolliPoP

In the browser console, in addition to displaying the result of obj.toString(), you get a reference to the object and can see its current state. But you are watching the console after the second function has been executed. Put a breakpoint in the right place and you will see the value at the moment of executing a particular line.
In order to output values ​​to the console at the time of calling console.log, you must either display the values ​​of specific object properties (unless, of course, these are objects that you mutate in the future), or display values ​​in a new object (again, only if the properties are primitive values):
either convert target object in JSON string:

console.log(JSON.stringify(obj));
console.log(JSON.stringify(obj, null, ' ')); // красивый вывод с отступами

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question