javascript:harmony
目次
ECMAScript Harmony
ECMAScript 6th Editionのこと
追加メソッド
追加されるかもしれないメソッド
Object.is
2つの値が等しいか判定。===とほぼ同じだが、NaNと0の扱いが異なる
if (!Object.is) { Object.is = function(v1, v2) { if (v1 === 0 && v2 === 0) return 1 / v1 === 1 / v2; if (v1 !== v1) return v2 !== v2; return v1 === v2; }; }
Number .isInteger
値が整数かどうか判定。
if (!Number.isInteger) { Number.isInteger = function isInteger (nVal) { return typeof nVal === "number" && isFinite(nVal) && nVal > -9007199254740992 && nVal < 9007199254740992 && Math.floor(nVal) === nVal; }; }
String.prototype.startsWith
String.prototype.startsWith = function(s) { return this.indexOf(s) === 0; };
String.prototype.endsWith
String.prototype.endsWith = function(s) { var t = String(s); var index = this.lastIndexOf(t); return index >= 0 && index === this.length - t.length; };
String.prototype.contains
String.prototype.contains = function(s) { return this.indexOf(s) !== -1; };
String.prototype.toArray
String.prototype.toArray = function() { return this.split(''); };
javascript/harmony.txt · 最終更新: 2013/07/11 08:42 by nullpon