question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Obj.set should default to constructor defaults

See original GitHub issue
Description of the problem

Consider this:

const a = new Vector3(4,5) // -> 4,5,0
a.set(1,2)
console.log(a) // -> 1,2,undefined

This is how the constructor is defined:

function Vector3(x, y, z) {
  this.x = x || 0;
  this.y = y || 0;
  this.z = z || 0;
}

And this is the set function:

function set(x, y, z) {
  this.x = x;
  this.y = y;
  this.z = z;
  return this;
}

It would be helpful and safer to assume constructor defaults always, for all objects that carry a set. Otherwise it’s throwing undefined into the renderer.

Here’s an example for instance that causes undefined behaviour where it works on some platforms but crashes on others: https://discourse.threejs.org/t/need-some-help-with-a-texture-that-doesnt-work-on-mobile/10553/2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
Mugen87commented, Nov 1, 2019

No problem, this discussion is really hard to find^^.

@mrdoob To recap: The idea is to make the parameters of all .set() methods optional. If no arguments are provided, the current property value does not change (rather than assigning undefined or set a ctor default value). One could argue that we already do this in Euler.set() but we all know that Euler._order is somewhat special.

0reactions
drcmdacommented, Nov 8, 2019

well, not in typescript (i would assume). but either way, you can do this today as well. and it’s valid code (but sometimes kills the renderer due to undefined being treated as a number without checks).

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Default value for options object in class constructor
Save this question. Show activity on this post. I've created a class and I would like to set some default options for values...
Read more >
Default constructors (C++ only) - IBM
A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values. If...
Read more >
5.2. Writing Constructors — AP CSAwesome
If there are no constructors written for a class, Java provides a no-argument default constructor where the instance variables are set to their...
Read more >
Default Constructor in Java – Class Constructor Example
In this article, we will talk about constructors, how to create our own constructors, and what default constructors are in Java.
Read more >
Default constructors - cppreference.com
5) Defaulted default constructor outside of class definition (the class must contain a declaration (1)). Such constructor is treated as user- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found