File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments