はじめに
こんにちは~。みなさんお元気でしたか。
本日は、JScriptで利用できる関数をまとめてみました。いつも何となく使えるだろう古いメソッドを利用しているのですが、明確にどれが使えるのか調べたことがなかったので、調査をしました。
JScirptの機能集
JScriptとは
利用できるメソッドなどを紹介する前に、JScript言語について少し説明したいと思います。
詳細に説明すると長くなりますが、簡単に説明するとWindows用のJavaScriptに似た言語です。この言語を使って、拡張子をjsとすることで、バッチファイルとして実行することができます。
バッチファイルといえば、Windows7から標準搭載されたPowerShellなどが機能が豊富で有名です。JScript自体は、1996年に公開されて以来、2009年の5.8系で機能が止まっています。ただ、JavaScriptが利用できるというのが非常に大きいメリットになっています。
ただ、上記で記載した通り、ECMAScript 5以降の機能がJScriptには搭載されていません。そのため、今の書き方に慣れてしまっていると、使えない機能を誤って使うといったことがあります。今回はそれらの利用できる機能をまとめていきたいと思います。
なお、JavaScriptはプロトタイプベースの言語であり、オブジェクトをクラスのように利用できるということで、厳密にはクラスとは言えないかもしれませんが、ここでは分かりやすくクラス、定数、関数などと呼んで説明します。
文法
JScriptで利用できる文法をまとめていきます。
特徴としては、let / const が利用できないという点があります。全てvarで代用する必要があります。
| 文法 | JScript |
| switch | OK |
| new | OK |
| delete | OK |
| try / catch / finally / throw | OK |
| let/const | NG |
| class | NG |
|
export / import
|
NG |
|
get / set
|
NG |
Global
グローバルオブジェクトをまとめます。ここでは有名なものをピックアップして、全ては羅列していません。
| 種類 | 名前 | JScript 5.8 |
| クラス | Array | OK |
| クラス | console | NG |
| クラス | Date | OK |
| クラス | JSON | NG |
| クラス | Math | OK |
| クラス | Number | OK |
| クラス | Object | OK |
| クラス | RegExp | OK |
| クラス | String | OK |
| 定数 | Infinity | OK |
| 定数 | NaN | OK |
| 定数 | globalThis | NG |
| 定数 | null | OK |
| 定数 | undefined | OK |
| 関数 | decodeURI | OK |
| 関数 | decodeURIComponent | OK |
| 関数 | encodeURI | OK |
| 関数 | encodeURIComponent | OK |
| 関数 | escape | OK |
| 関数 | eval | OK |
| 関数 | isFinite | OK |
| 関数 | isNaN | OK |
| 関数 | parseFloat | OK |
| 関数 | parseInt | OK |
| 関数 | unescape | OK |
上記の特徴としては、JSONが使えないというところがあります。evalで代用しましょう。globalThis は以下のようにすることで代用が可能です。
var globalThis = ( function() { return this; } ).apply( null, [] );
以下は、JScriptでのみ使えるグローバルオブジェクトです。WScriptとWSHは同一です。
| 種類 | 名前 |
| クラス | ActiveXObject |
| クラス | Error |
| クラス | GetObject |
| クラス | Enumerator |
| クラス | VBArray |
| クラス | WScript |
| クラス | WSH |
| 定数 | ScriptEngine |
| 定数 | ScriptEngineBuildVersion |
| 定数 | ScriptEngineMajorVersion |
| 定数 | ScriptEngineMinorVersion |
String
文字列を扱うクラスです。
HTMLと書いてある部分は、HTML wrapper method(HTML ラッパーメソッド)と呼ばれているものです。ウェブ標準からは削除されており、JScriptでのみしか利用できなくなる日が来るかと思われます。
特徴としては、Unicode系のメソッドがNGだということ。あとは、startsWith / endsWith / trimメソッドが使えないというのが辛いところです。
| 種類 | 名前 | JScript 5.8 |
| static | fromCharCode | OK |
| static | fromCodePoint | NG |
| static | raw | NG |
| get | length | OK |
| get | N | NG |
| method | charAt | OK |
| method | charCodeAt | OK |
| method | codePointAt | NG |
| method | concat | OK |
| method | includes | NG |
| method | endsWith | NG |
| method | indexOf | OK |
| method | lastIndexOf | OK |
| method | localeCompare | OK |
| method | match | OK |
| method | normalize | NG |
| method | padEnd | NG |
| method | padStart | NG |
| method | repeat | NG |
| method | replace | OK |
| method | search | OK |
| method | slice | OK |
| method | split | OK |
| method | startsWith | NG |
| method | substr | OK |
| method | substring | OK |
| method | toLocaleLowerCase | OK |
| method | toLocaleUpperCase | OK |
| method | toLowerCase | OK |
| method | toSource | NG |
| method | toString | OK |
| method | toUpperCase | OK |
| method | trim | NG |
| method | trimStart | NG |
| method | trimLeft | NG |
| method | trimEnd | NG |
| method | trimRight | NG |
| method | valueOf | OK |
| HTML | anchor | OK |
| HTML | big | OK |
| HTML | blink | OK |
| HTML | bold | OK |
| HTML | fixed | OK |
| HTML | fontcolor | OK |
| HTML | fontsize | OK |
| HTML | italics | OK |
| HTML | link | OK |
| HTML | small | OK |
| HTML | strike | OK |
| HTML | sub | OK |
| HTML | sup | OK |
Array
配列やハッシュマップなどを扱えるクラスです。
辛いところは、isArrayが利用できないところでしょうか。
| 種類 | 名前 | JScript 5.8 |
| static | from | NG |
| static | isArray | NG |
| static | of | NG |
| get | length | OK |
| method | concat | OK |
| method | copyWithin | NG |
| method | entries | NG |
| method | every | NG |
| method | fill | NG |
| method | filter | NG |
| method | find | NG |
| method | findIndex | NG |
| method | flat | NG |
| method | flatMap | NG |
| method | forEach | NG |
| method | includes | NG |
| method | indexOf | NG |
| method | join | OK |
| method | keys | NG |
| method | lastIndexOf | NG |
| method | map | NG |
| method | pop | OK |
| method | push | OK |
| method | reduce | NG |
| method | reduceRight | NG |
| method | reverse | OK |
| method | shift | OK |
| method | slice | OK |
| method | some | NG |
| method | sort | OK |
| method | splice | OK |
| method | toLocaleString | OK |
| method | toSource | NG |
| method | toString | OK |
| method | unshift | OK |
| method | values | NG |
| method | valueOf | OK |
Date
日付を扱うクラスです。なお、これ以外に日付を表すクラスとして、ActiveX 用のオブジェクト VT_DATE というのもあるので混在する際は注意してください。
Dateは、大体利用できますが、new Date(xxx)するときの文法で、ISO 形式の引数を受付できないなどといった問題があります。
| 種類 | 名前 | JScript |
| static | UTC | OK |
| static | now | NG |
| static | parse | OK |
| method | getDate | OK |
| method | getDay | OK |
| method | getFullYear | OK |
| method | getHours | OK |
| method | getMilliseconds | OK |
| method | getMinutes | OK |
| method | getMonth | OK |
| method | getSeconds | OK |
| method | getTime | OK |
| method | getTimezoneOffset | OK |
| method | getUTCDate | OK |
| method | getUTCDay | OK |
| method | getUTCFullYear | OK |
| method | getUTCHours | OK |
| method | getUTCMilliseconds | OK |
| method | getUTCMinutes | OK |
| method | getUTCMonth | OK |
| method | getUTCSeconds | OK |
| method | getYear | OK |
| method | setDate | OK |
| method | setFullYear | OK |
| method | setHours | OK |
| method | setMilliseconds | OK |
| method | setMinutes | OK |
| method | setMonth | OK |
| method | setSeconds | OK |
| method | setTime | OK |
| method | setUTCDate | OK |
| method | setUTCFullYear | OK |
| method | setUTCHours | OK |
| method | setUTCMilliseconds | OK |
| method | setUTCMinutes | OK |
| method | setUTCMonth | OK |
| method | setUTCSeconds | OK |
| method | setYear | OK |
| method | toDateString | OK |
| method | toGMTString | OK |
| method | toISOString | NG |
| method | toJSON | NG |
| method | toLocaleDateString | OK |
| method | toLocaleFormat | NG |
| method | toLocaleString | OK |
| method | toLocaleTimeString | OK |
| method | toSource | NG |
| method | toString | OK |
| method | toTimeString | OK |
| method | toUTCString | OK |
| method | valueOf | OK |
以下は、JScriptでのみ使える機能です。
| 種類 | 名前 |
| method | getVarDate |
Number
数値を扱うクラスです。
特徴としては、判別用のメソッドが全て利用できないというところがあります。
| 種類 | 名前 | JScript 5.8 |
| static get | EPSILON | NG |
| static get | MAX_SAFE_INTEGER | NG |
| static get | MAX_VALUE | OK |
| static get | MIN_SAFE_INTEGER | NG |
| static get | MIN_VALUE | OK |
| static get | NEGATIVE_INFINITY | OK |
| static get | NaN | NG |
| static get | POSITIVE_INFINITY | OK |
| static | isFinite | NG |
| static | isInteger | NG |
| static | isNaN | NG |
| static | isSafeInteger | NG |
| static | parseFloat | NG |
| static | parseInt | NG |
| method | toExponential | OK |
| method | toFixed | OK |
| method | toLocaleString | OK |
| method | toPrecision | NG |
| method | toSource | NG |
| method | toString | OK |
| method | valueOf | OK |
Math
数学用の定数や関数を提供するクラスです。
| 種類 | 名前 | JScript 5.8 |
| static get | E | OK |
| static get | LN2 | OK |
| static get | LN10 | OK |
| static get | LOG2E | OK |
| static get | LOG10E | OK |
| static get | PI | OK |
| static get | SQRT1_2 | OK |
| static get | SQRT2 | OK |
| static | abs | OK |
| static | acos | OK |
| static | acosh | NG |
| static | asin | OK |
| static | asinh | NG |
| static | atan | OK |
| static | atan2 | OK |
| static | atanh | NG |
| static | cbrt | NG |
| static | ceil | OK |
| static | cos | OK |
| static | cosh | NG |
| static | exp | OK |
| static | expm1 | NG |
| static | floor | OK |
| static | flound | NG |
| static | hypot | NG |
| static | imul | NG |
| static | log | OK |
| static | log10 | NG |
| static | log1p | NG |
| static | log2 | NG |
| static | max | OK |
| static | min | OK |
| static | pow | OK |
| static | random | OK |
| static | round | OK |
| static | sign | NG |
| static | sin | OK |
| static | sinh | NG |
| static | sqrt | OK |
| static | tan | OK |
| static | tanh | NG |
| static | trunc | NG |
Error
JScirpt 5.8 で try {} catch(e) {} で取得できるeのError オブジェクトです。
| 種類 | 名前 |
| get | description |
| get | name |
| get | number |
| get | message |
参考
以下の資料を利用して作成しました。
おわりに
おつかれさまです~。
今日は、使える機能をまとめてみました。今までなんとなく使っていたのですが、このようにまとまっていると、使える機能が明確ですぐに分かるので楽かもしれませんね。
ありがとうございました。



コメント
[…] 1番目は、JScriptの貧弱な機能を改善させます(参考:JScriptの仕様)。といっても全て実装したわけではなく、String型を中心によく利用すると思われる機能のみを追加しています。また、 […]