Obj.set should default to constructor defaults
See original GitHub issueDescription 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:
- Created 4 years ago
- Comments:12 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 assigningundefined
or set a ctor default value). One could argue that we already do this inEuler.set()
but we all know thatEuler._order
is somewhat special.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).