Make it to make it

いろいろ作ってアウトプットするブログ

javascript

2020年を迎えてのJavaScript Tips総ざらい

変数定義(var / let / const) var使うことはもうほとんどないし、今さらだが、重要なポイント。 var: function scoped undefined when accessing a variable before it's declared let: block scoped ReferenceError when accessing a variable before it'…

async/await再入門

asyncファンクション asyncファンクションが通常のファンクションと何が違うかは、以下の2つの例を見ればわかる。 function hello(ms) { return new Promise(resolve => setTimeout(() => { resolve('Hello from the other side!') }, ms)) } console.log(he…

Promise再入門(3)

Promiseを組み合わせる JavaScriptはPromiseの組み合わせのために、Promise.all()とPromise.race()という2つのビルトイファンクションが用意されている。 Promise.all() Promise.all()はpromiseからなる配列を組み合わせて、それらの処理結果を含むかたちで…

Promise再入門(2)

Promiseのthen()メソッドをコールすることは、既存のpromiseにハンドラをアサインするだけでなく新しいpromiseを作ることである。 const newPromise = promise.then(handleSuccess, handleRejection) Promiseチェーン successまたはerrorハンドラがpromiseを…

Promise再入門(1)

モダンなJavaScriptでは、非同期処理においてpromiseとasync/awaitが主流となっている。 Webpackはコードスプリッティングをpromiseによって簡便化している ブラウザにはビルトインファンクションであるfetchが存在し、resultをawaitできる ReactではReact.S…

Reduxのことをわかりやすく

Reduxイントロ Reduxとはアプリケーションの状態(state)を管理するためのJSライブラリ。 ではアプリケーションの状態とは具体的に何かというと、いろんな目的で後に使用する情報を保持しておくためのグローバルオブジェクト。 小さな例ではページロード時…

this: new binding, window binding

new binding /** * new Binding */ const Animal = function(color, name, type) { this.color = color this.name = name this.type = type } const zebra = new Animal('black and white', 'shimauma', 'plant-eating animal') console.log(zebra) 下記のよ…

this: Implicit binding / Explicit binding

Implicit binding 次のようなファクトリーファンクションがあるとする。 いわゆる実行時にオブジェクトを返却するファンクション。 /** * Implicit Binding * Left of the dot at call time */ const Person = function(name, age) { return { name, age, sa…