このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
js:function:basic [2021/04/12 14:31] tanaka |
js:function:basic [2021/04/19 13:05] (現在) tanaka [第1級オブジェクト] |
||
---|---|---|---|
行 21: | 行 21: | ||
</ | </ | ||
- | === 例 === | + | <sxh javascript; |
- | <code javascript> | + | |
console.log(getArea(10, | console.log(getArea(10, | ||
function getArea(height, | function getArea(height, | ||
return height * width; | return height * width; | ||
} | } | ||
- | </code> | + | </sxh> |
\\ | \\ | ||
行 36: | 行 35: | ||
</ | </ | ||
- | === 例 === | + | <sxh javascript; |
- | <code javascript> | + | |
var func1 = new Function(' | var func1 = new Function(' | ||
var func2 = new Function(' | var func2 = new Function(' | ||
行 43: | 行 41: | ||
console.log(func1(10, | console.log(func1(10, | ||
console.log(func2(10, | console.log(func2(10, | ||
- | </code> | + | </sxh> |
\\ | \\ | ||
行 55: | 行 53: | ||
</ | </ | ||
- | === 例 === | + | <sxh javascript; |
- | <code javascript> | + | |
var func = function(height, | var func = function(height, | ||
return height * width; | return height * width; | ||
}; | }; | ||
console.log(func(10, | console.log(func(10, | ||
- | </code> | + | </sxh> |
関数リテラルは、無名関数又は匿名関数とも呼ばれる。 | 関数リテラルは、無名関数又は匿名関数とも呼ばれる。 | ||
行 76: | 行 73: | ||
</ | </ | ||
- | === 例 === | + | <sxh javascript; |
- | <code javascript> | + | |
var func = (height, width) => { | var func = (height, width) => { | ||
return height * widht; | return height * widht; | ||
}; | }; | ||
console.log(func(10, | console.log(func(10, | ||
- | </code> | + | </sxh> |
+ | |||
+ | <sxh javascript; | ||
+ | var area = r => Math.PI * r * r; | ||
+ | console.log(area(10)); | ||
+ | </ | ||
+ | |||
+ | <sxh javascript; | ||
+ | var sayHello = () => console.log(' | ||
+ | sayHello(); | ||
+ | </sxh> | ||
\\ | \\ | ||
行 94: | 行 100: | ||
* 独自の存在をもつ(無名可能) | * 独自の存在をもつ(無名可能) | ||
- | === 例 === | + | <sxh javascript; |
- | <code javascript> | + | |
function func1(height, | function func1(height, | ||
| | ||
行 110: | 行 115: | ||
callFunc(3, 10, func3); | callFunc(3, 10, func3); | ||
callFunc(4, 10, func4); | callFunc(4, 10, func4); | ||
- | </code> | + | </sxh> |