Update:
Recently, in the spring of 2020, Google unveiled a new runtime for Apps Script that now includes support for Classes.
New scripts automatically utilize this updated runtime, while older scripts require conversion. A conversion prompt will appear in the script editor to guide you through the process.
// V8 runtime
class Rectangle {
constructor(width, height) { // class constructor
this.width = width;
this.height = height;
}
logToConsole() { // class method
console.log(`Rectangle(width=${this.width}, height=${this.height})`);
}
}
const r = new Rectangle(10, 20);
r.logToConsole(); // Outputs Rectangle(width=10, height=20)
Original (old) answer:
Traditionally, Javascript has been considered a "classless" language, as classes are a relatively newer concept that hasn't been widely embraced yet, and still aren't fully supported by Apps Script.
Here's how you can simulate class-like behavior in Apps Script:
var Polygon = function(height, width){
this.height = height;
this.width = width;
this.logDimension = function(){
Logger.log(this.height);
Logger.log(this.width);
}
};
function testPoly(){
var poly1 = new Polygon(1,2);
var poly2 = new Polygon(3,4);
Logger.log(poly1);
Logger.log(poly2);
poly2.logDimension();
}