JavaScript(ES2015ïŒES6ïŒ) ãðŸç«ã¡æ¢ãŸã£ãŠäžæŠåŸ©ç¿ð£â¡ð¥ð¥ððã
äžæŠåŸ©ç¿ç¬¬äºåŒŸâïž
ãProgate JavaScriptãâ
£ãâ
Šã
ååã®ãé¢æ°ããŸã§åŸ©ç¿ããçŽ10æ¥ã¶ãã§ãããèšé²ãã£ãŠã倧äºã§ããããããã©çŸå®ãçªãã€ãããããã⊠ãã©ãæ¹ç«ã¯ããªããâ
ProgateããŸã§å¿ããŠããç®æãåãã£ãŠãªãã£ãç®æãå確èªïŒ
ðãªããžã§ã¯ãã®åŸ©ç¿
ã// å®æ°animalãå®çŸ©ããŠãã ãã
ããconst animal = {
ãããname:"ã¬ãª" ,
ãããage:3 ,
ãããgreet : () => {ãconsole.log("ããã«ã¡ã¯");ã}
ãã};ãããââ ïžãïŒãå¿ããŠãð±
ã// animalã®nameð·ããããã£ã®å€ãåºåããŠãã ãã
ããconsole.log(animal.name);
ã// animalã®greetð·ããããã£ã®é¢æ°ãå®è¡ããŠãã ãã
ããanimal.greet();
ðã¯ã©ã¹ããçæãããªããžã§ã¯ãã¯ã€ã³ã¹ã¿ã³ã¹
ãâã€ã³ã¹ã¿ã³ã¹ãconsole.logãããšãclassã®ãªããžã§ã¯ããåºåããã
ãclass Animal {ã}
// Animalã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãå®æ°animalã«ä»£å
¥ããŠãã ãã
ãconst animal = new Animal ( ) ; ââ ïžðœã€ã³ã¹ã¿ã³ã¹ïŒåŒæ°çšã®ãïŒ ïŒã
// å®æ°animalã®å€ãåºåããŠãã ãã
ãconsole.log(animal);
ðã³ã³ã¹ãã©ã¯ã¿ïŒclassã®èšèšå³ïŒ
ãâã€ã³ã¹ã¿ã³ã¹ãçæãããçŽåŸã«å®è¡
ããclass Animal {
ã// ã³ã³ã¹ãã©ã¯ã¿ãè¿œå ããŠãã ãã
ãããconstructor ( ) {ããââ ïžðœåŒæ°çšã®ãïŒ ïŒãå¿ããŠãð±
ããããconsole.log("ã€ã³ã¹ã¿ã³ã¹ãçæããŸãã"); }
ããã}
ããconst animal = new Animal();
ðã³ã³ã¹ãã©ã¯ã¿ã®äžã§ãã€ã³ã¹ã¿ã³ã¹ã«é¢ããæ
å ±ãè¿œå
ãâã€ã³ã¹ã¿ã³ã¹ã¯ãã¯ã©ã¹ããçæãããªããžã§ã¯ã
ãâæ
å ±ã¯ããããããã£ïŒå€ãã§è¿œå ïŒthisïŒ
ã
ðã¡ãœããïŒã€ã³ã¹ã¿ã³ã¹ã®åäœïŒ
ãâã¡ãœããå
ã§ãã€ã³ã¹ã¿ã³ã¹ã®ãå€ããå©çšã§ããïŒãthis.ããããã£åãã䜿çšïŒ
ãâã¡ãœããå
ã§ä»ã®ã¡ãœãããå©çšããããšãå¯èœïŒãthis.ã¡ãœããå( )ãïŒ
ããð·ããããã£ã®é¢æ°ãå®è¡ã§ãåºæ¥ãâŠ
ð芪ã¯ã©ã¹ããã¡ãœãããåŒãç¶ãåã¯ã©ã¹
ãâåã¯ã©ã¹å
ã§ãæ°ã¡ãœãããäœæããæ»ãå€ãå©çšã§ããã
ããâ class Dog extends Animal {
ãããããããâ£getHumanAge(){
ãããããããããããããããâ€return this.age*7; } }
ããâ¡const dog = new Dog("ã¬ãª", â¥4);
ããâ¢dog.info();
ããâŠconst humanAge = dog.getHumanAge( );
ããâ§console.log(`人é幎霢ã§${humanAge}æ³ã§ã`);
ãâ â¡â¢âdogãšããŠããã¬ãªããšããæ°ããæ
å ±ãåºåãããã
ãâ£äººé幎霢ã衚瀺ãããããª
ãâ€ã¬ãªã®å¹Žéœ¢ãå
ã«äººé幎霢ãèšç®ããå€ããæ»ãå€ããšããŠä»£å
¥ã
ãâ¥ãæåã¯ãthis.ageã
ãâŠãâ£ã®åºåã«å¿
èŠãªå€ãå®çŸ©ïŒâ¥ã«å¯ŸããŠâ€ãäœããâ€ã䜿ããâ£ãåºåããããã«â¡ãçšããŠâŠãå®çŸ©ïŒã
ã⧠âŠãçšããŠæ
å ±ãåºåã
ðãªãŒããŒã©ã€ãïŒã¡ãœãããã³ã³ã¹ãã©ã¯ã¿ïŒ
ããâåã¯ã©ã¹ã芪ã¯ã©ã¹ãäžæžã
ããclass Animal {
ããããconstructor(name, age) {
ãããããããããããããããããthis.name = name;
ãããããããããããããããããthis.age = age;}
ããããgreet() {
ããããããããconsole.log("ããã«ã¡ã¯");}
ããããinfo() {
ããããããããthis.greet();
ããããããããconsole.log(`ååã¯${this.name}ã§ã`);
ããããããããconsole.log(`${this.age}æ³ã§ã`);}
ãã}
ããclass Dog extends Animal {
ããããgetHumanAge() {
ãããããããããããããreturn this.age * 7;}
ããããinfo(){
ããããããããthis.greet();
ããããããããconsole.log(`ååã¯${this.name}ã§ã`);
ããããããããconsole.log(`${this.age}æ³ã§ã`);}
ãããã ããðœconst humanAge = this.getHumanAge();
ããããã ãðœconsole.log(`人é幎霢ã§${humanAge}æ³ã§ã`);}
ãã}
ããããconst dog = new Dog("ã¬ãª", 4);
ã ãðœdog.info();
2h30mããã£ããã§ããâŠ
ä»åã¯1ïœçšã§ããããã£ã±ããŸãšããŠã¬ããã§ãããšç¹ãããåãããããã£ãã§ããã
ðã¯ã©ã¹ãå®çŸ©å
export default Animal;
ããâimport Animal from "./animal";
ðååä»ããšã¯ã¹ããŒã
ãâdefaultãæžããã«ãååã{}ã§å²ãã§ãšã¯ã¹ããŒããã
ðçžå¯Ÿãã¹
ããã£ã¬ã¯ããªã®ç§»åïŒ ./ / ïŒãšãéå±€ã®ç§»åïŒ ../ ïŒ
ðããã±ãŒãžã«ã€ããŠ
ãâãã®æã¯äžæè°ã®åœã®ãŠãŒãã³ã§ããããä»ã¯ã³ã©ã ãçµã埩ç¿ãçµããŠãç¡äºã«çŸå®äžçã«æ»ã£ãŠããããããªæ°ãããŸãðœâïž çŸå®äžçã§ãããŠãŒãã³ðœããšãããŒã¢ã«ðžãã®éãã«æ°ã¥ããèšæ£ãã次第ã§ãðŸã€ã ãã£ã«å€©æŽ¥é£¯ãæ飯ã«ããžãŒã¿ãæ¹ããŠããã©ãŽã³ããŒã«ã®äžç芳ãããã§ããâš
ðã³ãŒã«ããã¯é¢æ°ïŒ push ã forEach ã find ã filter ã map ïŒ
ãåŒæ°ã«å
¥ã£ãŠããé¢æ°
ããforEachã
ãconst characters = ["ã«ãããããã", "ãã€ããŒããã", "ã²ã€ãä»äºº", "ãšãããã"];
// forEachã¡ãœããã䜿ã£ãŠãé
åcharactersã®äžèº«ããã¹ãŠåºåããŠãã ãã
characters.forEach ( (character) => {console.log(character);} );
ããããââ ïžforEachïŒ ïŒãåºæ¬
ããããããââ ïžåŒæ° character ã¯åæ°ã
ããforEachã
ãconst names = [
ãããããããããã{firstName: "Kate", lastName: "Jones"},
ãããããããããã{firstName: "John", lastName: "Smith"},
ãããããããããã{firstName: "Denis", lastName: "Williams"},
ãããããããããã{firstName: "David", lastName: "Black"}ã];
ã// å®æ°namesã«mapã¡ãœããã䜿ã£ãŠæ°ããé
åãäœããå®æ°fullNamesã«ä»£å
¥ããŠãã ãã
ãconst fullNames = names.map((name) => {
ãããããããããreturn name.firstName + name.lastName ;ã});
ãããââ ïžå®æ°ã§ã¯ãªããåŒæ°ã®ã name . ããå¿ããŠãð±
ã// å®æ°fullNamesãåºåããŠãã ãã
ãconsole.log(fullNames);
ðã³ãŒã«ããã¯é¢æ°
ãconst printWanko = () => {
ããããconsole.log("ã«ãããããã");ã};
ãconst call = (callback) => {
ããããconsole.log("ã³ãŒã«ããã¯é¢æ°ãåŒã³åºããŸãã");
ããããcallback();ã};ããâðœé¢æ°ãåŒã³åºã
ãããããããããããããããâ ïžåŒæ°ã代å
¥ãããšåŒã³åºããªãïŒ
ãcall(printWanko);ãããâcallã®é¢æ°ãåŒã³åºããæã
ããããããããããããããconsoleãšåŒæ°ã«ä»£å
¥ãããé¢æ°ãåºåã
ããããããããããããããâ ïžåŒæ°ã代å
¥ãããŠããéã¯ãã³ãŒã«ããã¯é¢æ°ã§ãåŒæ°ã代å
¥ããªããšåºåã§ããªãã
ðã¿ãŒããã«ã«ã€ããŠ
HomebrewãðœmacOSïŒãŸãã¯Linuxã·ã¹ãã ïŒã®æ©èœãè£å®
â
nodebrewãðœnode.jsã®ããŒãžã§ã³ç®¡çããŒã«
ããããããïŒè€æ°ã®node.jsã®ããŒãžã§ã³ãç°¡åã«åãæ¿ããããïŒ
â
node.jsããðœãµãŒããŒãµã€ãã®JavaScriptå®è¡ç°å¢
ããããããããnode.jsã§ãã¡ã€ã«ãå®è¡ããéã¯ã
ãããããããããnode ãã¡ã€ã«åããšã¿ãŒããã«ã«å
¥å
â
npmãããðœnode.jsã®ããã±ãŒãžç®¡çã¢ããª
ããããããâpackage.jsonã
ããããããð·ãnpm initãã§çæãããnode.jsã®èšå®ç®¡çãã¡ã€ã«
â
babelãããðœæ°ããèŠæ Œã§èšè¿°ãããã³ãŒããES5ãªã©ã®
ãããããããå€ãèŠæ Œã«æžãæããïŒã³ã³ãã€ã©ïŒããã±ãŒãž
ããããããð·package.jsonã«ãbabelã³ãã³ããç»é²ãã
ðnpmããã±ãŒãž
ããŸãšãã
ãã¯ã埩ç¿ãšããåã®å埩緎ç¿ã¯ãšãŠã倧åã ãšå®æãã次第ã§ãâŠ
çŽ2ã¶æåã«èŠãæããã¯ã ãã¶ã€ã¡ãŒãžãã€ããŠæ¥ãããã«ãªãïŒããããããð ïŒãProgateæ§ã§ãã£ãŠããããšã®å確èªã次ã®åŠç¿ããžã§ã³ãèŠããŠããŸããðð±
ãŸãã
è¿œå åŠç¿ã§æ¢ãäžã§ãããªã®ãèŠã€ããŠå°ããã£ãŠã¿ãŸããã
ïŒGitHubã§ã®ãã°ã€ã³ãå¯èœã ã£ã£ãããïŒãããŒãŒãŒãŒãŒãŒã⊠ã€ãã€ã(ï¿£âï¿£;) éææã«æ¬ ããâŠ
ãšãããã
ãããæ°ã®ããã°ãæ¹ããŠèŠãŠããŸã ãŸã ãŸã âŠéåã°ã§ããããšã®å®æããhtml /cssã«ããäžåæ»ã£ãŠç·Žç¿ãããæ°æã¡ãªã©ãåºãŠããŸããŠâŠ
ãããããâŠçŠãâŠððð
ããå°ãä»ãµã€ãã§JavaScriptã®åŠç¿ããã©èŠããŠããã次ãå®ããŸãÙ©( 'Ï' )Ù
ãã®èšäºãæ°ã«å ¥ã£ãããµããŒããããŠã¿ãŸãããïŒ