This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var answer = 42; | |
answer = "いままで魚をありがとう..."; | |
//上記は問題なし |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hoge(cnt) { | |
cnt = 3; | |
} | |
var cnt = 1; | |
hoge(cnt); | |
console.log('カウント:' + cnt); //"カウント:1"が表示される |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunc(theObject) { | |
theObject.make = "Toyota"; | |
} | |
var mycar = {make: "Honda", model: "Accord", year: 1998}; | |
var x, y; | |
x = mycar.make; // x は "Honda" という値になる | |
myFunc(mycar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(i) { | |
if (i < 0) | |
return; | |
console.log('begin:' + i); | |
foo(i - 1); | |
console.log('end:' + i); | |
} | |
foo(3); | |
// 出力内容 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [ | |
"Hydrogen", | |
"Helium", | |
"Lithium", | |
"Beryllium" | |
]; | |
var a2 = a.map(function(s){ return s.length }); | |
var a3 = a.map( s => s.length ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myObj = new Object(), | |
str = "myString", | |
rand = Math.random(), | |
obj = new Object(); | |
myObj.type = "Dot syntax"; | |
myObj["date created"] = "String with space"; | |
myObj[str] = "String value"; | |
myObj[rand] = "Random Number"; | |
myObj[obj] = "Object"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showProps(obj, objName) { | |
var result = ""; | |
for (var i in obj) { | |
if (obj.hasOwnProperty(i)) { | |
result += objName + "." + i + " = " + obj[i] + "\n"; | |
} | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//厳密に等しい (===) | |
//厳密等価演算子はオペランド同士が、型を変換することなく (上に示した通り) 厳密に等しいならば真を返します。 | |
3 === 3 // true | |
3 === '3' // false | |
//厳密には等しくない (!==) | |
//厳密不等価演算子は、オペランド同士が等しくない、型が等しくない、あるいはその両方ならば真を返します。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//敵を作る | |
function Teki(){ | |
this.hp = 100; | |
} | |
//ドラゴンを作る | |
function Dragon(){ | |
Teki.apply(this,arguments); | |
} | |
Dragon.prototype = new Teki; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//敵を作る | |
function Teki(n){ | |
this.name = n; | |
} | |
//現れる | |
Teki.prototype.appear = function(){ | |
console.log(this.name+"が あらわれた!"); | |
}; | |
//攻撃 | |
Teki.prototype.attack = function(){ |