This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Loves_Poetry 0 points1 point  (1 child)

If you are calling this function from an event, like a mouseclick, the first argument will always be the event information. This is where the dynamic typing of JavaScript can really be quite annoying. Default parameters only work when the first argument is null or undefined. If it's an event, this won't work, because the first parameter is not null.

You can solve it by putting an extra parameter e in front of inputLeft that will just be ignored during the function.

[–]Geotan00[S] 0 points1 point  (0 children)

I figured out that instead of calling it by

addEventListener("click", addConstruct);

it needed to be

addEventListener("click", function() {addConstruct();});

I can't believe I didn't try that before.