Closed utillity closed 6 years ago
that's because if (conn != null)
- check staright for null or undefined. It's up to you.
sorry, I don't get it. Changing code to the following yields same result (error and crash):
if (conn == null)
{
console.log("Connection established with " + ip);
conn = new Connection(ip, "Unknown");
state.connections.push(conn);
}
else
{
if (conn.status != "Active")
{
conn.status = "Active";
conn.connectedSince = Date.now();
console.log("Connection reestablished with " + ip);
}
}
Cannot comment if I haven't a demo or test repo.
ok, found the problem. my class has a ctor with parameters. Had to add another ctor which would also init the properties. Not very nice to have to do that, though.
function Connection(ip, desc) {
this.ipAddress = ip;
this.description = desc;
this.status = "Active";
this.connectedSince = Date.now();
}
Connection.prototype = {
ipAddress: null,
description: null,
status: "Active",
connectedSince: Date.now()
};
undefined != null // false
undefined !== null // true
the mistake is here if (conn == null)
If I understand it right the problem was solved, I am closing this issue. Reopen if needed.
this is my code adding a new entry to state.connections:
on pushing conn to state.connections, I get the following error: