公式ドキュメントによると Google Apps Script のベースは JavaScript1.8 相当ということなのですが、「ブラウザにはあるあのメソッドってApps Scriptで使えたっけ?」とよく悩むのでメモ。
Object
Object - staticメンバ
- create
- defineProperties
- defineProperty
- freeze
- getOwnPropertyDescriptor
- getOwnPropertyNames
- getPrototypeOf
- isExtensible
- isFrozen
- isSealed
- keys
- preventExtensions
- prototype
- seal
Object - インスタンスメンバ
- __defineGetter__
- __defineSetter__
- __lookupGetter__
- __lookupSetter__
- constructor
- hasOwnProperty
- isPrototypeOf
- propertyIsEnumerable
- toLocaleString
- toSource
- toString
- valueOf
Array
Array - staticメンバ
- concat
- every
- filter
- forEach
- indexOf
- isArray
- join
- lastIndexOf
- map
- pop
- prototype
- push
- reduce
- reduceRight
- reverse
- shift
- slice
- some
- sort
- splice
- unshift
Array - インスタンスメンバ
- concat
- constructor
- every
- filter
- forEach
- indexOf
- join
- lastIndexOf
- length
- map
- pop
- push
- reduce
- reduceRight
- reverse
- shift
- slice
- some
- sort
- splice
- toLocaleString
- toSource
- toString
- unshift
String
String - staticメンバ
- charAt
- charCodeAt
- concat
- equalsIgnoreCase
- fromCharCode
- indexOf
- lastIndexOf
- localeCompare
- match
- prototype
- replace
- search
- slice
- split
- substr
- substring
- toLocaleLowerCase
- toLowerCase
- toUpperCase
String - インスタンスメンバ
- anchor
- big
- blink
- bold
- charAt
- charCodeAt
- concat
- constructor
- equals
- equalsIgnoreCase
- fixed
- fontcolor
- fontsize
- indexOf
- italics
- lastIndexOf
- length
- link
- localeCompare
- match
- replace
- search
- slice
- small
- split
- strike
- sub
- substr
- substring
- sup
- toLocaleLowerCase
- toLocaleUpperCase
- toLowerCase
- toSource
- toString
- toUpperCase
- trim
- valueOf
メンバ一覧の取得に使ったスクリプト
function reportBasicTypeMembers() {
var objects = [
{foo: 'bar'}, // Oject
['1'], // Array
new String(''),
];
var report = {};
for (var i = 0; i < objects.length; ++i) {
var instance = objects[i];
var ctor = instance.constructor;
var proto = Object.getPrototypeOf(instance);
var reportEntry = {
constructor: ctor.name,
staticMembers: Object.getOwnPropertyNames(ctor)
.filter(function(name) {
return -1 == ['arguments', 'arity', 'name', 'length'].indexOf(name);
})
.sort(),
instanceMembers: Object.getOwnPropertyNames(proto).sort(),
};
report[reportEntry.constructor] = reportEntry;
}
var json = JSON.stringify(report, null, 2);
// Logger.log だと途中で切れる
SpreadsheetApp.getActiveSpreadsheet()
.getActiveCell()
.setValue(json);
}