Skip to content

Commit 3d38e07

Browse files
authored
not using global-state mode.
1 parent e973b84 commit 3d38e07

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

src/math/math.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,36 @@ function math(p5, fn) {
103103
* </div>
104104
*/
105105
fn.createVector = function (x, y, z) {
106+
const argc = arguments.length;
106107

107-
if (arguments.length === 0 && typeof p5 !== 'undefined' && p5._friendlyError) {
108+
if (argc === 0 && typeof p5 !== 'undefined' && p5._friendlyError) {
108109
p5._friendlyError(
109110
'Calling createVector() with no arguments is deprecated and will be removed in a future release. Pass zeros for the desired dimensionality.'
110111
);
111112
}
112-
this.dimension = arguments.length;
113113
const safeArgs =
114-
arguments.length === 1 ? [x, 0, 0]
115-
: arguments.length === 2 ? [x, y, 0]
116-
: [...arguments];
117-
114+
argc === 1 ? [x, 0, 0]
115+
: argc === 2 ? [x, y, 0]
116+
: [...arguments];
117+
118+
let v;
118119
if (this instanceof p5) {
119-
return new p5.Vector(
120+
v = new p5.Vector(
120121
this._fromRadians.bind(this),
121122
this._toRadians.bind(this),
122123
...safeArgs
123124
);
124125
} else {
125-
return new p5.Vector(...safeArgs);
126+
v = new p5.Vector(...safeArgs);
126127
}
128+
129+
Object.defineProperty(v, '_origDimension', {
130+
get() { return argc; },
131+
});
132+
133+
return v;
127134
};
135+
128136

129137
/**
130138
* Creates a new <a href="#/p5.Matrix">p5.Matrix</a> object.

0 commit comments

Comments
 (0)