きったんの頭ん中☆
JavaScript メモ
リンク
サンプル
ライブラリ
CommonJS
文
- {}
- break [label]
- const
- continue [label]
- do...while
- for [[each]...in]
- function
- if[...else]
- label
- let
- return
- switch
- throw
- try...catch
- var
- while
IE hack
var isMSIE = /*@cc_on!@*/false;
<!--[if IE]><![endif]-->
スコープ
ブロックスコープでなく関数スコープ
(function(){
var private = 'private';
publicFunction = function(){return 'public';};
function innerObject(property){
this.property = property;
}
innerObject.prototype = {
toString:function(){return this.property;},
accessPrivate:function(){return private;}
};
window.innerObject = innerObject;
}());
strict モード
"use strict";
"use asm";
演算子
- 算術演算子 (+ - * / % ++ --)
- 代入演算子 (= += -= *= /= >>= <<= >>>= &= |= ^=)
- ビット演算子 (& | ^ ~ << >> >>>)
- 比較演算子 (== != === !== > >= < <=)
- 論理演算子 (&& || !)
- 文字列演算子 (+ +=)
- メンバー演算子 (object.property, object["property"])
- 条件演算子 (condition ? ifTrue : ifFalse)
- コンマ演算子 (,)
- delete
- function
- get
- in
- instanceof
- let
- new
- set
- this
- typeof
- void
- yield
優先順位
降順
- . [] new
- ()
- ++ --
- ! ~ * / % + - typeof void delete
- + -
- << >> >>>
- < <= > >= in instanceof
- == != === !==
- &
- ^
- |
- &&
- ||
- ? :
- 代入演算子
- ,
型変換
Number
- +a, a*1, Number(a), parseFloat(a)
- a|0, parseInt(a)
String
- a+'', String(a), a.toString()
Boolean
グローバル・プロパティ
グローバル関数
- decodeURI
- decodeURIComponent
- encodeURI
- encodeURIComponent
- isFinite
- isNaN
- parseFloat
- parseInt
Object
- getPrototypeOf(object)
- hasOwnProperty(prop)
- isPrototypeOf
- propertyIsEnumerable(prop)
- toString([radix])
- toLocaleString
- valueOf()
- constructor
- Object.prototype.newName
ECMAScript 5
- create
- defineProperty
- defineProperties
- getOwnPropertyDescriptor
- getOwnPropertyNames
- keys
- preventExtensions
- isExtensible
- seal
- isSealed
- freeze
- isFrozen
Function
new Function([arg1[, …],] function)
ECMAScript 5
arguments
Array
Properties
Methods
- sort([function])
- reverse()
- pop()
- shift()
- unshift(e1, …)
- push(e1, …)
- splice(start, n, e1, …)
- slice(start)
- concat(array1, …)
- join(separator)
- toString()
ECMAScript 5
- indexOf(searchElement [, fromIndex])
- lastIndexOf(searchElement [, fromIndex])
- isArray
- filter(callback [, thisObject])
- forEach(callback [, thisObject])
- every(callback [, thisObject])
- map(callback [, thisObject])
- some(callback [, thisObject])
- reduce(callback [, initialValue])
- reduceRight(callback [, initialValue])
Boolean
true
7, '0', {}, []
false
0, '', null
Date
- parse(string)
- UTC(year, mon, day, hour, min, sec)
- getTime()
- setTime(time)
- getFullYear()
- setFullYear(year)
- getMonth()
- setMonth(mon)
- getDate()
- setDate(date)
- getDay()
- getHours()
- setHours(hour)
- getMinutes()
- setMinutes(min)
- getSeconds()
- setSeconds(sec)
- getMilliseconds()
- setMilliseconds(msec)
- getUTCFullYear()
- setUTCFullYear(year)
- getUTCMonth()
- setUTCMonth(mon)
- getUTCDate()
- setUTCDate(date)
- getUTCDay()
- getUTCHours()
- setUTCHours(hour)
- getUTCMinutes()
- setUTCMinutes(min)
- getUTCSeconds()
- setUTCSeconds(sec)
- getUTCMilliSeconds()
- setUTCMilliSeconds(msec)
- getTimezoneOffset()
- toString()
- toLocaleString()
- toUTCString()
ECMAScript 5
- now()
- toJSON()
- toISOString()
Error
new Error([message [, fileName [, lineNumber]]])
- EvalError
- RangeError
- ReferenceError
- SyntaxError
- TypeError
- URIError
try{
throw new Error('Whoops!');
}catch(e){
if(e instanceof EvalError){
alert(e.name +': '+ e.message);
}
}
Number
>Math.pow(2, 53)
9007199254740992
>Math.pow(2, 53) + 1
9007199254740992
>Math.pow(2, 53) === Math.pow(2, 53) + 1
true
>10100401822940525
10100401822940524
The Case of the Disappearing Number
Properties
- NaN
- MAX_VALUE
- MIN_VALUE
- POSITIVE_INFINITY
- NEGATIVE_INFINITY
Methods
- toExponential([fractionDigits])
- toFixed([digits])
- toPrecision([precision])
- toString(radix)
- toLocaleString(radix)
- valueOf()
String
var str = "String";
- fromCharCode(num1, …)
- length
- charAt(n)
- charCodeAt(n)
- substring(from [, to])
- slice(from [, to])
- substr(from [, length])
- split([sep [, limit]])
- concat(string)
- replace(before, after[, flag])
- toUpperCase()
- toLowerCase()
- toLocaleUpperCase()
- toLocaleLowerCase()
- indexOf(key [, from])
- lastIndexOf(key [, from])
- match(regexp)
- search(regexp)
- valueOf()
- localeCompare()
ECMAScript 5
RegExp
var regex = new RegExp("pattern" [, "flags"]);
var literal = /pattern/flags;
- RegExp(patern [, flag(g|i|m|y)])
- g : 一致するすべて
- i : 大文字・小文字を無視
- m : 複数行
- y : stickyフラグ
- compile(patern [, flag(g|i|m|y)])
- ignoreCase
- global
- source
- exec([str])
- test([str])
- match([regexp])
- lastIndex
- RegExp.$n
- multiline / $*
- input / $_
- lastMatch / $&
- leftContext / $`
- rightContext / $"
- lastParen / $+