Skip to content

Commit 7a808ae

Browse files
authored
Merge pull request #6807 from asukaminato0721/Default-values-of-arguments
Default values of arguments && modernize some code
2 parents b862aef + 5fc46d5 commit 7a808ae

19 files changed

+305
-507
lines changed

src/color/creating_reading.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ p5.prototype.brightness = function(c) {
290290
* @param {p5.Color} color
291291
* @return {p5.Color}
292292
*/
293-
p5.prototype.color = function() {
294-
p5._validateParameters('color', arguments);
295-
if (arguments[0] instanceof p5.Color) {
296-
return arguments[0]; // Do nothing if argument is already a color object.
293+
p5.prototype.color = function(...args) {
294+
p5._validateParameters('color', args);
295+
if (args[0] instanceof p5.Color) {
296+
return args[0]; // Do nothing if argument is already a color object.
297297
}
298298

299-
const args = arguments[0] instanceof Array ? arguments[0] : arguments;
300-
return new p5.Color(this, args);
299+
const arg = Array.isArray(args[0]) ? args[0] : args;
300+
return new p5.Color(this, arg);
301301
};
302302

303303
/**

src/core/p5.Renderer2D.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class Renderer2D extends p5.Renderer {
452452
(this.width * pixelsState._pixelDensity) +
453453
x * pixelsState._pixelDensity);
454454
if (!pixelsState.imageData) {
455-
pixelsState.loadPixels.call(pixelsState);
455+
pixelsState.loadPixels();
456456
}
457457
if (typeof imgOrCol === 'number') {
458458
if (idx < pixelsState.pixels.length) {
@@ -462,7 +462,7 @@ class Renderer2D extends p5.Renderer {
462462
a = 255;
463463
//this.updatePixels.call(this);
464464
}
465-
} else if (imgOrCol instanceof Array) {
465+
} else if (Array.isArray(imgOrCol)) {
466466
if (imgOrCol.length < 4) {
467467
throw new Error('pixel array must be of the form [R, G, B, A]');
468468
}

src/core/shape/2d_primitives.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ p5.prototype.ellipse = function(x, y, w, h, detailX) {
292292
* </div>
293293
*
294294
*/
295-
p5.prototype.circle = function() {
296-
p5._validateParameters('circle', arguments);
297-
const args = Array.prototype.slice.call(arguments, 0, 2);
298-
args.push(arguments[2]);
299-
args.push(arguments[2]);
300-
return this._renderEllipse(...args);
295+
p5.prototype.circle = function(...args) {
296+
p5._validateParameters('circle', args);
297+
const argss = args.slice( 0, 2);
298+
argss.push(args[2], args[2]);
299+
return this._renderEllipse(...argss);
301300
};
302301

303302
// internal method for drawing ellipses (without parameter validation)

src/core/shim.js

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +0,0 @@
1-
// requestAnim shim layer by Paul Irish
2-
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
3-
// http://my.opera.com/emoller/blog/2011/12/20/
4-
// requestanimationframe-for-smart-er-animating
5-
// requestAnimationFrame polyfill by Erik Möller
6-
// fixes from Paul Irish and Tino Zijdel
7-
window.requestAnimationFrame = (() =>
8-
window.requestAnimationFrame ||
9-
window.webkitRequestAnimationFrame ||
10-
window.mozRequestAnimationFrame ||
11-
window.oRequestAnimationFrame ||
12-
window.msRequestAnimationFrame ||
13-
((callback, element) => {
14-
// should '60' here be framerate?
15-
window.setTimeout(callback, 1000 / 60);
16-
}))();
17-
18-
/**
19-
* shim for Uint8ClampedArray.slice
20-
* (allows arrayCopy to work with pixels[])
21-
* with thanks to http://halfpapstudios.com/blog/tag/html5-canvas/
22-
* Enumerable set to false to protect for...in from
23-
* Uint8ClampedArray.prototype pollution.
24-
*/
25-
(() => {
26-
if (
27-
typeof Uint8ClampedArray !== 'undefined' &&
28-
!Uint8ClampedArray.prototype.slice
29-
) {
30-
Object.defineProperty(Uint8ClampedArray.prototype, 'slice', {
31-
value: Array.prototype.slice,
32-
writable: true,
33-
configurable: true,
34-
enumerable: false
35-
});
36-
}
37-
})();
38-
39-
/**
40-
* this is implementation of Object.assign() which is unavailable in
41-
* IE11 and (non-Chrome) Android browsers.
42-
* The assign() method is used to copy the values of all enumerable
43-
* own properties from one or more source objects to a target object.
44-
* It will return the target object.
45-
* Modified from https://github.com/ljharb/object.assign
46-
*/
47-
(() => {
48-
if (!Object.assign) {
49-
const keys = Object.keys;
50-
const defineProperty = Object.defineProperty;
51-
const canBeObject = obj => typeof obj !== 'undefined' && obj !== null;
52-
const hasSymbols =
53-
typeof Symbol === 'function' && typeof Symbol() === 'symbol';
54-
const propIsEnumerable = Object.prototype.propertyIsEnumerable;
55-
const isEnumerableOn = obj =>
56-
(function isEnumerable(prop) {
57-
return propIsEnumerable.call(obj, prop);
58-
});
59-
60-
// per ES6 spec, this function has to have a length of 2
61-
const assignShim = function assign(target, source1) {
62-
if (!canBeObject(target)) {
63-
throw new TypeError('target must be an object');
64-
}
65-
const objTarget = Object(target);
66-
let s, source, i, props;
67-
for (s = 1; s < arguments.length; ++s) {
68-
source = Object(arguments[s]);
69-
props = keys(source);
70-
if (hasSymbols && Object.getOwnPropertySymbols) {
71-
props.push(
72-
...Object.getOwnPropertySymbols(source)
73-
.filter(isEnumerableOn(source))
74-
);
75-
}
76-
for (i = 0; i < props.length; ++i) {
77-
objTarget[props[i]] = source[props[i]];
78-
}
79-
}
80-
return objTarget;
81-
};
82-
83-
defineProperty(Object, 'assign', {
84-
value: assignShim,
85-
configurable: true,
86-
enumerable: false,
87-
writable: true
88-
});
89-
}
90-
})();

src/core/transform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ p5.prototype.scale = function(x, y, z) {
431431
x = v.x;
432432
y = v.y;
433433
z = v.z;
434-
} else if (x instanceof Array) {
434+
} else if (Array.isArray(x)) {
435435
const rg = x;
436436
x = rg[0];
437437
y = rg[1];
@@ -443,7 +443,7 @@ p5.prototype.scale = function(x, y, z) {
443443
z = 1;
444444
}
445445

446-
this._renderer.scale.call(this._renderer, x, y, z);
446+
this._renderer.scale(x, y, z);
447447

448448
return this;
449449
};

src/dom/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3278,7 +3278,7 @@ p5.Element.prototype.hide = function () {
32783278
*/
32793279
/**
32803280
* @method size
3281-
* @param {Number|Constant} w width of the element, either AUTO, or a number.
3281+
* @param {Number|Constant} [w] width of the element, either AUTO, or a number.
32823282
* @param {Number|Constant} [h] height of the element, either AUTO, or a number.
32833283
* @chainable
32843284
*/

0 commit comments

Comments
 (0)