The Size object is used to describe the size or dimensions of something, through its width and height properties.
Example — Create a size that is 10pt wide and 5pt high, and use it to define a rectangle:
var size = new Size(10, 5); console.log(size.width); // 10 console.log(size.height); // 5 var rect = new Rectangle(new Point(20, 15), size); console.log(rect); // { x: 20, y: 15, width: 10, height: 5 }
Creates a Size object with the given width and height values.
Example — Create a size that is 10pt wide and 5pt high
var size = new Size(10, 5); console.log(size.width); // 10 console.log(size.height); // 5
Creates a Size object using the numbers in the given array as dimensions.
Example — Creating a size of width: 320, height: 240 using an array of numbers:
var array = [320, 240]; var size = new Size(array); console.log(size.width); // 320 console.log(size.height); // 240
Creates a Size object using the properties in the given object.
Example — Creating a size of width: 10, height: 20 using an object literal:
var size = new Size({ width: 10, height: 20 }); console.log(size.width); // 10 console.log(size.height); // 20
Returns the addition of the supplied value to the width and height of the size as a new size. The object itself is not modified!
Example
var size = new Size(5, 10); var result = size + 20; console.log(result); // {width: 25, height: 30}
Returns the addition of the width and height of the supplied size to the size as a new size. The object itself is not modified!
Example
var size1 = new Size(5, 10); var size2 = new Size(10, 20); var result = size1 + size2; console.log(result); // {width: 15, height: 30}
Returns the subtraction of the supplied value from the width and height of the size as a new size. The object itself is not modified!
The object itself is not modified!
Example
var size = new Size(10, 20); var result = size - 5; console.log(result); // {width: 5, height: 15}
Returns the subtraction of the width and height of the supplied size from the size as a new size. The object itself is not modified!
Example
var firstSize = new Size(10, 20); var secondSize = new Size(5, 5); var result = firstSize - secondSize; console.log(result); // {width: 5, height: 15}
Returns the multiplication of the supplied value with the width and height of the size as a new size. The object itself is not modified!
Example
var size = new Size(10, 20); var result = size * 2; console.log(result); // {width: 20, height: 40}
Returns the multiplication of the width and height of the supplied size with the size as a new size. The object itself is not modified!
Example
var firstSize = new Size(5, 10); var secondSize = new Size(4, 2); var result = firstSize * secondSize; console.log(result); // {width: 20, height: 20}
Returns the division of the supplied value by the width and height of the size as a new size. The object itself is not modified!
Example
var size = new Size(10, 20); var result = size / 2; console.log(result); // {width: 5, height: 10}
Returns the division of the width and height of the supplied size by the size as a new size. The object itself is not modified!
Example
var firstSize = new Size(8, 10); var secondSize = new Size(2, 5); var result = firstSize / secondSize; console.log(result); // {width: 4, height: 2}
The modulo operator returns the integer remainders of dividing the size by the supplied value as a new size.
Example
var size = new Size(12, 6); console.log(size % 5); // {width: 2, height: 1}
The modulo operator returns the integer remainders of dividing the size by the supplied size as a new size.
Example
var size = new Size(12, 6); console.log(size % new Size(5, 2)); // {width: 2, height: 0}
Checks whether the width and height of the size are equal to those of the supplied size.
Example
var size = new Size(5, 10); console.log(size == new Size(5, 10)); // true console.log(size == new Size(1, 1)); // false console.log(size != new Size(1, 1)); // true
Returns a copy of the size.
Checks if this size has both the width and height set to 0.
Checks if the width or the height of the size are NaN.
Copyright © 2011 Jürg Lehni & Jonathan Puckey. All Rights Reserved.