投稿時間:2021-07-06 21:41:34 RSSフィード2021-07-06 21:00 分まとめ(46件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 「女子学生が選ぶ2021年上半期トレンド大賞」1位は「コムドット」  下半期のトレンド予測1位は? https://www.itmedia.co.jp/business/articles/2107/06/news138.html itmedia 2021-07-06 20:52:00
IT ITmedia 総合記事一覧 [ITmedia News] NFC搭載の“段ボールコントローラー”でスマホを操作、給電はワイヤレス 凸版印刷が新技術 https://www.itmedia.co.jp/news/articles/2107/06/news142.html itmedianewsnfc 2021-07-06 20:45:00
IT ITmedia 総合記事一覧 [ITmedia News] シーパラで「あつ森」コラボ ゲーム中の魚など100種以上を展示 https://www.itmedia.co.jp/news/articles/2107/06/news139.html itmedia 2021-07-06 20:04:00
IT MOONGIFT ニューテゴミン - 手書きの明朝体フォント http://feedproxy.google.com/~r/moongift/~3/FjJ7gE-RgXs/ 紹介 2021-07-06 21:00:00
python Pythonタグが付けられた新着投稿 - Qiita 「PyWebIO」があればPython 100%でWebアプリ作れるってマジ!? https://qiita.com/payaneco/items/51a11a8063b7f0654561 難しいけどここを乗り越えれば簡単にWebアプリを作ることができるから頑張って挑戦してみてねpipinstallpywebioコーディングほとんど全部が本家のユーザーズガイドからのオマージュだけどそれで要件は足りる。 2021-07-06 20:37:37
python Pythonタグが付けられた新着投稿 - Qiita Python Coding Test - easy https://qiita.com/justNOZA/items/a9dfde2904c71565998c PythonCodingTesteasy電話番号リストLevel問題要約phonebook電話帳を配列します。 2021-07-06 20:27:44
python Pythonタグが付けられた新着投稿 - Qiita Python + Arduino でGUIからロボットアームを制御してみた https://qiita.com/BNM_13579/items/da5989a73910531ec325 サーボモータドライバPCAとArduinoを用いて複数個のサーボモータmgrを動かす模式図実機プログラム・動作環境WindowsHomePythonArduinoIDEArduinoUnoR・ArduinoArduinoに書き込むコードはこちらの方を参考にしました。 2021-07-06 20:18:49
python Pythonタグが付けられた新着投稿 - Qiita 自分とこの環境下におけるPython使用ルール https://qiita.com/NeK/items/6456664cde0ec125368a 2021-07-06 20:11:18
js JavaScriptタグが付けられた新着投稿 - Qiita JavaScript 関数型プログラミング まとめ https://qiita.com/Islanders-Treasure0969/items/36dc66af3d683a4c5d3a JavaScript関数型プログラミングまとめ概要今までVBなどのOOPにばかり慣れ親しんできていた関数型プログラミングという言葉は知っているが、その実態を全く理解できていないJavaScriptでは関数型プログラミングを意識することでいいことがあるようなので、学んだことをまとめる関数型プログラミングとは参照透過的な関数を組みあわせて解決すべき問題を対処する宣言型のプログラミングスタイルのことプログラミングパラダイムからみる関数型プログラミングプログラミングのパラダイムの大分類命令型プログラミング最終的な出力を得るために状態を変化させる連続した文によって記述されるプログラミングスタイルのこと命令方に分類される代表的なパラダイム手続き型プログラミングC言語等オブジェクト志向プログラミングRuby等宣言型プログラミング出力を得る方法ではなく、出力の性質・あるべき状態を文字通り宣言することでプログラムを構成する「どうやって得るか」ではなく、「何を得たいか」というアプローチ宣言型プログラミングの代表例ははSQLこの宣言型プログラミングというのは、意味的に二つ存在する一つは上記の内容二つ目は、関数型プログラミング、論理プログラミング、制約プログラミング、の総称の意味つまり、関数型プログラミングは宣言型プログラミングのうちのつである手続き型と比較した関数型プログラミングの利点オブジェクトが基本的にイミュータブルなので、プログラムの予測可能性が高い手続き形プログラミングでは、変数がミューダブル可変である場合が多く、繰り返しの処理などではその間のステップで予期せぬバグが混入する確率が高くなる不変性を守ることでプログラムから副作用が排除される関数型プログラミングでは、副作用をなるべく排除するために変数への代入も極力行わないようにする代入しなければ壊れるものもないためメソッドチェーンで式を繋ぎ、関数自体もその場限りの無名関数を使用する手続き形では「文」を使用する一方で関数型では「式」を組みあわせてサログラムを構成する手続き形ではfor分の中でif文などで条件分岐したりする関数型プログラミングでは、すべてが値を返す式の組み合わせでありそれが左辺から右辺へ評価されていき最終的な値へ到達する形になっているそれぞれの式が独立しており、相互に干渉がないので度に考えることが少なくて済むメソッドチェーンで式をつないだり、関数自体に無名関数を使用する理由プログラミングのアプローチ手続き形はボトムアップ的に積み上げていったものが最終的な成果物となる関数型では最初から大雑把なものを作り上げてそこから絞り込んでいくメソッドチェーンの例でいうと、リソースに対してltresourcegtfiltersomethingなどとしていくことで、左に大雑把なものリソースが存在しメソッドチェーンでリソースに対してフィルタリングや値の加工などの特定の処理をしていくことで目的のデータに仕上げていくイメージJavaScriptでのコレクションの配列処理map渡した配列を処理して新しい配列を返す下記例では、配列arrに対してmapを使用して、要素に対してした結果をmapに格納しているconstarrconstmaparrmapxgtxconsolelogmapfilter渡した配列の中で条件に当てはまる値を抽出する下記例では、配列arrに対してfilterを使用して、要素の中でで割り切れる要素をfilterに格納しているconstarrconstfilterarrfilterxgtxconsolelogfilterfind渡した配列で条件に適合した最初の値を返す下記例では、配列arrに対して、要素の並びで最初にで割り切れる要素をfindに格納しているfindでは、最初の値というのが分かりやすいように、arrを降順にした並びに対して最初にで割り切れる要素を格納しているconstarrconstfindarrfindxgtxconstfindarrsortabgtagtbfindxgtxconsolelogfindconsolelogfindfindindex渡した配列で条件に適合した最初のインデックスを返す下記例では上記のfindのインデックスを返すのと同じfindIndexとsortの中身を関数化したconstarrconstdivxgtxconstdescsortxygtxgtyconstfindarrfindIndexdivconstfindarrsortdescsortfindIndexdivconsolelogfindconsolelogfindevery渡した配列が条件を全て満たすかを真偽値で返すconstarrconstarrconstdivxgtxconsteveryarreverydivconsteveryarreverydivconsolelogeverytrueconsolelogeveryfalsesome渡した配列に条件を満たす値がつでもあるかを真偽値で返すconstarrconstarrconstoverxgtxgtconstsomearrsomeoverconstsomearrsomeoverconsolelogsomefalseconsolelogsometruereduceレシーバーの配列に対して、引数の関数を実行し、最終的に一つの値を返す引数を以下のように取り、単一の処理を実行する第一引数に実行値が蓄積される値第二引数に現在処理される配列の要素constarrconsttotalxygtxyconstreducearrreducetotalconsolelogreducesortレシーバーの配列に対して、引数の関数を実行し、配列を並び替えるsortは破壊的メソッドなので、レシーバーに対して実行すると、変数に代入しても元の配列も並び変えてしまうconstarrconstdescsortxygtxgtyconstarrarrsortdescsortconsolelogarrconsolelogarr上記の例では、元の配列まで並び替えられてしまっているsliceを間に入れることで元の配列を並び替えずに実行できるsliceは、元は引数にstartとendを指定することで、レシーバーの配列から指定のインデックス間の要素をコピーすることができる関数は引数なしであれば元の配列全体をコピーすることになるので、コピーした配列に対して破壊的メソッドを実行しても元の配列は変更されないconstarrconstdescsortxygtxgtyconstarrarrslicesortdescsortconsolelogarrconsolelogarrincludesメソッド指定した値の要素が一つでも配列に含まれているかを真偽値で返すArrayのプロトタイプメソッドconstarrconstincludesarrincludesconstincludesarrincludesconsolelogincludestrueconsolelogincludesfalsex組み込みオブジェクトObjectの反復処理についてxオブジェクトのキー名一覧を取得するObjectkeysltobjectNamegtで、ltobjectNamegtで指定したObjectオブジェクトのキーの一覧を取得するconstobjnameuserageconsolelogObjectkeysobjnameagexオブジェクトの値一覧を取得するObjectvaluesltobjectNamegtで、ltobjectNamegtで指定したObjectオブジェクトの値の一覧を取得するconstobjnameuserageconsolelogObjectvaluesobjuserxオブジェクトのキーと値の一覧を取得するObjectentriesltobjectNamegtで、ltobjectNamegtで指定したObjectオブジェクトのキーと値の一覧を取得するconstobjnameuserageforconstkeyvalueofObjectentriesobjconsolelogkeyisvaluenameisuserageis関数のカリー化カリー化とは複数の引数を取る関数を、引数をもとの関数の最初の引数で戻り値が最初の関数の引数としての残りの引数をとりそれを使って結果を返す関数である高階関数化すること※カリー化の定義について上記のカリー化の定義は、必ずしもすべてのコンテキストにおいて成り立つものではないとのこと関数が「カリー化」されていない言語でカリー化について定義するのであれば上記の定義が成り立つがHaskellなどのすべての関数がカリー化されているような言語でのカリー化の定義はまた別とのこと以下詳細カリー化のサンプルxとyを引数にとって加算する「二引数の関数」をplusという「一引数を取る関数のチェイン」に直した例constplusfunctionxreturnfunctionyreturnxyconsolelogplusカリー化された関数の部分的用カリー化された関数の一部の引数を固定して新しい関数を作ることカリー化された関数は、変数に代入する時に引数を省略すると、残りの引数を残した戻り値の関数を変数に代入することが出来る下記の例ではplusという関数がまず存在するplusは、yを引数に取った関数をxを引数に取った関数でカリー化してある関数。 2021-07-06 20:43:58
js JavaScriptタグが付けられた新着投稿 - Qiita JavaScriptまとめ https://qiita.com/Islanders-Treasure0969/items/2f5833284753ea16231c JavaScriptまとめ概要今まで業務でJavaScriptは使用したことはないが、PFで使用する事にした後で見返すときに簡単に理解出来るようにまとめるりあクトという書籍で勉強した変数宣言についてJSでは昔から使用されているvarがある変数宣言では、varは使わず、letもしくはconstで宣言する以下で変数名と再代入、再宣言の可否をまとめた変数名再代入再宣言var可能可能let可能不可const不可不可varのさらなるデメリットとして変数スコープは関数単位である他の大多数の言語ではブロックスコープであるため、挙動が読みにくいプリミティブ型についてプリミティブ型とはオブジェクトではなく、メソッドをもたないデータの事プリミティブ型のデータは、それ自体を変更することは出来ず、代入する事でしか新しい値にできない又、プリミティブ型を定義するときはリテラルを使用する必要があるプリミティブ型一覧BooleanTrueおよびFalseの二つの真偽値を扱うデータ型trueとfalseの真偽値リテラルで定義出来るNumber型数値を扱うためのデータ型整数も小数も同じNumber型になる数値リテラルで定義出来るやなど先頭にxをつけることで進数を表現できるoをつけることで進数を表現できるbをつけることで進数を表現できるなどの形式は不動小数点リテラルと呼ぶBigInt型Number型では扱えない数値を扱うデータ型Number型とは互換性がないので代入や計算、等値比較はできないnのように数字の後ろにnをつけて表現する数値リテラルで定義出来るString型文字列を扱うためのデータ型、またはで囲む文字リテラルバッククウォートを用いると改行を含む複数行テキストやによる式展開が可能なテンプレートリテラルになるSymbol型シンボル値という固有の識別子を表現する値オブジェクトのプロパティキーとして使用可能Null型プリミティブ値Nullは何のデータも存在しない状態を明示的に表す際に使用するnullリテラルであるnullはプリミティブ型nullを返すしかし、typeof演算子でnullのデータ型を調べるとobjectとなるらしいUndefined型宣言のみが行われた変数や、オブジェクト内の存在しないプロパティへのアクセスに割り当てられる他の多くの言語と異なり、Nullと明確に区別されるundefinedというのは実際はグローバル変数であるプリミティブ値のリテラルとラッパーオブジェクトについてプリミティブ型ではインスタンスメソッドを持たないはずが、実際は使用できるなぜかラッパーオブジェクトのおかげである本当ははラッパーオブジェクトはnew演算子と対応するコンストラクタ関数を利用している作成する事になるだが、明示的にラッパーオブジェクトを指定しなくてもプリミティブ型のデータに対してアクセスする時はその対応するラッパーオブジェクトに自動変換するという仕組みがあるこの仕様によって、明確に異なるプリミティブ型とオブジェクト型の間で同じインスタンスメソッドが利用できるオブジェクト型のリテラルについて上記のプリミティブ型に対応するリテラル以外のリテラルを見ていく配列リテラルsamplejsconstArrリテラルで定義constArrnewArrayArrayオブジェクトをコンストラクタで定義当然だが、配列リテラルでは、配列の要素を直接指定する事になるよって、Arrayオブジェクトとはこの様な差が生まれるsamplejsconstArrArrgtgtconstArrnewArrayArrgtgtemptyemptyemptyオブジェクトリテラルsamplejsオブジェクトリテラルの宣言constobjnameIslandersTreasureage定義したオブジェクトリテラルはobjkeyまたはobjkeyで取得できるsamplejsobjnamegtgtIslandersTreasureobjagegtgt正規表現リテラルpaternfragsの形式で記述する正規表現パターンでの特殊文字の使い方は他の言語と同じRegExpオブジェクトのインスタンスとして生成されるsamplejsletreabcJavaScriptにおけるオブジェクト広義のオブジェクトと狭義のオブジェクトという風にコンテキストによって意味が変わる狭義のオブジェクトの定義一般的なクラスベースのオブジェクト指向言語ではクラスインスタンスのことを「オブジェクト」と呼称するjavascriptでのオブジェクトはキーとそれに対応する値を持ったプロパティの集まり一般的には連想配列と呼ばれるRubyのハッシュに相当するもの広義のオブジェクトの定義プリミティブ値以外のすべてのものを包括して指す広義のオブジェクトはすべてObjectという標準組み込みオブジェクトを最終的な継承元に持っているプリミティブ型はオブジェクトではないObjectオブジェクトを継承しているのではなく、あくまでリテラル値で表現される値であるため関数の定義についてプログラムにおける文と式違い式値を生成し、変数に代入できる物具体的には、リテラルsample、変数foo、関数呼び出しの事指揮と演算子の組み合わせも式というsamplejsconstcntsample文変数に代入できないもの何らかの手続きを処理系に命令するものsamplejsconstisTruetrueifisTrueセミコロンつける場所文の場合文の末尾にはセミコロンが必要のブロックで終わる場合にはつけないという例外規則がある式の場合逆に関数式のほうは最終的に変数への代入文になっているため末尾にセミコロンをつける必要がある第一級オブジェクトとは以下のような特徴を有するオブジェクトのこと変数への代入samplejsletaaagtconsolelogHelloaaagtgtHelo配列の要素やオブジェクトのプロパティ値になれるsamplejsletobjnameaaaagegt他の関数に引数として渡す事ができる別の関数の戻り値として設定できるJavaScriptでは、関数は第一級オブジェクトとして扱われるアロー関数JavaScriptの関数式従来の関数の代替構文samplejs従来の関数constaddOnefunctionnreturnn従来の関数をアロー関数に書き換えsamplejsアロー関数constaddOnengtreturnn本文がreturn文だけの時はreturn文をブロックごと省略できるsamplejsアロー関数なしconstaddTwoArgsabgtreturnn引数がひとつの時は引数のも省略できるsamplejsアロー関数ampなしconstaddOnengtn無名関数匿名関数関数の名前は、関数式などで定義したものについては、functionインスタンスとしてのnameプロパティに格納されている定義時に名前を与えられない関数を無名関数と呼ぶ名前付き関数自体は、関数で閉じたローカル変数なので、外部から呼び出すことはできない関数の中でのみ呼び出すことができるletxconstsampleFuncfunctionlocalFuncifxxconsolelogHellolocalFuncsampleFuncgtgtHellolocalFuncgtgtエラーアロー関数でのnameプロパティgtnameではnameプロパティは無い名前が無いのでメモリに残らず、変数に代入されなければ定義しても参照できない無名関数は変数に代入することで、nameプロパティに変数名が格納されるのでメモリに保存されるgtconsoleloghelloこのままではメモリに残らないので、どこからも参照できないconstsampleFuncgtconsoleloghellosampleFuncgtgthello引数の表現デフォルト引数関数の引数に対してデフォルト引数を設定できるVBでいう引数のOptionalでの宣言みたいなもんconstmultiplyababgtabconsolelogmultiplygtgtconsolelogmultiplygtgtデフォルト引数を設定するときデフォルト値がある引数は引数の後ろにまとめて設定すること関数の設計として重要な値ほど前に持ってくるべきだからレストパラメーター残りの引数を配列として受け取ることが出来るもの関数の最後の引数の名前に「」のプレフィックスをつけることで残りの引数を配列で受け取ることができるconstsampleabcgtletansabcmapelementgtanselementconsoleloganssamplegtgtレストパラメータにそれぞれ名前をつけたい場合constsumi…jklgtijklただし、定義してある以上の引数が受け渡された場合は切り捨てられるクラス構文実態は特別な関数であるJSのクラスにはクラス式とクラス宣言があるクラス宣言classsampleconstructornameagethisnamenamethisageageクラス式constaaaclassconstructorheightwidththisheightheightthiswidthwidthゲッターgetareareturnthiscalcAreaインスタンスメソッドcalcAreareturnthisheightthiswidth静的メソッドクラスメソッドstaticsayHelloconsolelogHelloconstsamplenewaaaconsolelogsampleareagtgtaaasayHellogtgtHelloextendsで親クラスを継承した子クラスを作ることができる他のオブジェクト指向言語と同じsuperで継承元のクラスにメンバー変数を渡すことができるJavaScriptにおけるコンストラクタ関数とはプロトタイプオブジェクトを継承してオブジェクトインスタンスを生成するための独立した関数のことプロトタイプベースのオブジェクト指向プロトタイプベースではオブジェクトの抽象としてのクラスが存在しない「オブジェクトの抽象としてのクラスがある」とはクラスベースでは、オブジェクトの下になるクラスが存在するこれをもとにオブジェクトを作成するこれを「オブジェクトの抽象としてのクラスがある」と表現するプロトタイプベースでのオブジェクトプロトタイプベースでは、オブジェクトの抽象となるのはクラスではないオブジェクトの抽象となるのはほかのオブジェクトを継承するその時の継承元になったオブジェクトをオブジェクトプロトタイプと呼ぶコンストラクタ関数とは広義のオブジェクトに設定されているプロトタイプオブジェクトを継承して新しくオブジェクトインスタンスを生成するための関数例constarrnewArrayarrというArrayオブジェクトを定義するためのコンストラクタ関数はArrayconststrnewStringsamplestrというStringオブジェクトを定義するためのコンストラクタ関数はStringプリミティブ型のラッパーオブジェクト値がそれぞれ使えてるメソッドはオブジェクトインスタンスの継承元であるプロトタイプが持ってるメソッドを継承したものJavaScriptではあらゆるオブジェクトは何らかのプロトタイプを継承していて、その「プロトタイプチェーン」は最終的には空オブジェクトを経てnullに到達する配列やオブジェクトの便利な構文オブジェクトのキー名と値をそれぞれ動的に設定する例keyとbazオブジェクトのキーで変数を参照する際はkeyのようにで囲む必要があるconstkeybarconstbazconstobjfookeybazbazconsolelogobjfoobarbazプロパティのショートハンドオブジェクトのキーと値を事前に変数で定義しているときに使用できる構文オブジェクトの中で変数bazの名前がプロパティのキー名に、値がそのプロパティ値になってるconstbazconstobjbazconsolelogobjbaz分割代入通常の分割代入Rubyの多重代入に似たようなものconstnmconsolelognmオブジェクトを分割代入するときの高度なテクニックObjectオブジェクトを定義するとき、Objectのキーと同じキーで分割代入することができるconstobjnameKanaeageconstnameageobjconsolelognameageKanaeスプレッド構文コレクション型のオブジェクトを展開する際に使用する構文本質はレストパラメーターと同じ以下で使用用途を解説する配列の展開任意の配列を展開する際に使用する通常は、配列内の要素に配列変数を指定すると、つの要素として配列が存在することになるレストパラメーターを配列の要素に指定することで、配列変数内の要素を指定の配列に展開することができる下記例ではarrでレストパラメーターを指定して配列展開をしているarrでは要素に直接配列を指定しているので、配列の要素に配列がそのまま入っているconstarrABCconstarrarrDEconstarrarrDEconsolelogarrABCDEconsolelogarrABCDEオブジェクトの展開任意のオブジェクト内に展開する際に使用する配列と同じで、変数をそのままオブジェクトのキーに指定すると、値にオブジェクトが入るだけになってしまうレストパラメーターを指定することで、指定のオブジェクトの中にレストパラメーターで指定したオブジェクトを展開できる下記例ではarrでレストパラメーターを指定してオブジェクトを展開をしているarrでは要素に直接オブジェクトを指定しているので、キーに変数名、値にオブジェクトがそのまま入っているconstobjabcdconstobjobjdeconstobjobjdeconsolelogobjabcdeconsolelogobjobjabcdde上記の分割代入とスプレッド構文を組み合わせることで分割代入で一部の値を受け取り、他の値をスプレッド構文で受け取るといった高度なことが可能になるショートサーキット評価短絡評価、他他の言語と同様、複数の条件が存在する場合に左辺から評価し、真偽が決まった時点で残りを評価せずに値を返すことができるOptionalChainingプロパティアクセス修飾子の後にをつけて、指定したキーが存在しなかった時にundefinedを返すための機能なぜ必要かオプショナルなオブジェクトに対してオブジェクトチェーンを使用してアクセスするソースを書いているときに通常であれば各階層の値がundefinedかどうかをチェックする処理を各必要があるこのチェックを行わずに下層のプロパティにアクセスするしたいから通常のオブジェクトチェーン階層目のプロパティが存在しない場合はundefinedが返る階層目にないプロパティを指定して階層目を指定するとエラーになってしまう通常のオブジェクトチェーンでは階層目で存在しなくても階層目までアクセスしてしまうため、エラーとなってしまう階層目であるかどうかのチェックを入れてから階層目にアクセスする処理を入れる必要があったconstadventurernameAlicecatnameDinahconsolelogadventurerdogundefinedifadventurerdogundefinedconsolelogadventurerdognameadventurerdogがundefinedでない時だけadventurerdognameにアクセスするconsolelogadventurerdognameコメントアウトするとエラーが返るオブジェクトチェーンにを使用するを使うとチェーン内の各参照が正しいかどうかを明示的に確認せずにアクセスしていくことが出来るプロパティアクセス修飾子の後にをつけることでオブジェクトチェーンの各階層で短絡評価をするようにできる途中のプロパティが存在していなかったらそこで式が短絡されてundefinedが返るconstadventurernameAlicecatnameDinahconsolelogadventurerdognameundefinedNullishCoalescing左辺がnull又はundefinedの時に右辺が評価される機能なぜ必要か左辺が空文字やの時に右辺を評価したい時があるやは直感的には明示的に指定している値かはわからないこれらを意図的に使用している場合に、truthyな値として評価させたいため通常の処理通常では、処理系がや空文字をfalsyな値と判断するため、その場合は右辺を評価して上書きされてしまうfoooはnullなのでこれはどちらでもfalsyな値と判断できるbazzは左辺がであり、明示的にそうなっているときでも処理系がfalsyと判断して上書きされるconstfooonulldefaultstringconsolelogfooodefaultstringconstbazzconsolelogbazzを使えば、より厳密にfalsyな値を判定できるやを明示的に指定している場合はを使うことで、左辺はtruthyな値と判断して、上書きされないfooはnullなのでこれはどちらでもfalsyな値と判断できるbazは左辺がであり、を使用することでtruthyと判断させて、左辺のみで短絡させるconstfoonulldefaultstringconsolelogfoodefaultstringconstbazconsolelogbazxOptionalChainingとNullishCoalescingの組み合わせ上記の二つの機能を使用することででオブジェクトチェーンで下層のプロパティにアクセスするときに直感的にソースを書くことができるでオブジェクトがやであり、且つそれをtruthyに扱いたいときも直感的に書くことができるオブジェクトに対する操作がより直感的になるnullとundefinedとの闘いが楽になるthisについてthisとはその関数が実行されるコンテキストであるオブジェクトの参照が格納されている引数のこと以下のようなコンテキストがある関数・メソッド内での呼び出しこの時のthisの参照はその関数・メソッドをプロパティとして持つオブジェクトへの参照オブジェクトのメソッド内以下では、sampleオブジェクトが、aaaというキーでメソッドプロパティを格納しているこのメソッドの中でのthisのコンテキストはメソッドをプロパティとして持っているsampleオブジェクトなので、thissampleとなるvarsamplenameuseraaafunctionconsolelogthisnameobjaaauserthissampleより、samplenameとなる※JavaScriptにおけるプロパティとはObjectオブジェクトでいう、特定のキーをもとに公開するデータや値のこと以下は、sampleオブジェクトの中に、nameキーでuserというプロパティが格納されているconstsamplenameuser関数内関数式を宣言しているスコープがグローバルスコープである場合この時のthisのコンテキストはグローバルオブジェクトWindowになるconstaaauserconstsamplefuncfunctionconsolelogthisaaasamplefuncuserthisWindowより、Windowaaaとなるコンストラクタ内での呼び出し特定のインスタンスを生成するとき、new演算子に続けてコンストラクタ関数を使用するnewArrayとかこの時のthisのコンテキストは新たに生成されるインスタンスを参照する下の例ではsampleクラスにnameキーとageキーで値を格納するようにしているよって、インスタンス化するときに、コンストラクタ内のthisが参照するのはインスタンスであるsampleとなるconstsampleclassconstructorthisnamenamethisageageconstsampleinstncenewsampleuserconsolelogsampleinstancenameuserthissampleinstanceより、sampleinstancenameとなるapplycallでの呼び出しapply、とcallは特別なメソッドで、thisのコンテキストを変更することができる下の例では、sampleのsamplefuncメソッドのコンテキストは、メソッドのプロパティをもっているオブジェクトであるsampleになるよって、samplesamplefuncではuserと出力されるそれを、applyでthisのコンテキストをsampleに変更することでthisnameがsamplenameになるのでadminと出力されるconstsamplenameusersamplefuncfunctionconsolelogthisnameconstsamplenameadminsamplesamplefuncusersamplesamplefuncapplysampleadminstrictモードでのグローバルオブジェクトESで追加された機能であるstrictモードでは、それ以前のグローバルオブジェクトとコンテキストが異なるES以前の仕様メソッドでない関数オブジェクトのプロパティではない関数はthisのコンテキストにグローバルオブジェクトをとるこの仕様上、簡単にグローバル汚染を起こせてしまうことが問題であったES以降の仕様strictモード有効の時メソッドでない関数のthisにundefinedが入る仕様になった関数のコンテキストがグローバルオブジェクトの場合は参照しないことになったJavaScriptのthisの挙動による弊害クラス構文でstrictモードの時に困ることメソッド内で関数を使用する時が困るstrictモードの時は、メソッド内で使用する関数にはコンテキストがない通常のオブジェクト指向言語では、一つ外のスコープを参照することを期待するので、この挙動の違いは悩ましい以下のprofileで定義しているメソッドの中でsetTimeout関数を使用しているこの中の関数のthisのコンテキストはグローバルオブジェクトとなり、通常はstrictモードが有効なので、undefinedとなるconstsamplenameuserageprofilefunctionconsolelogHiMynameisthisnamesetTimeoutfunctionconsolelogthisageyearsoldsampleprofileHiMynameisuserundefinedyearsoldクラス内のメソッドでアロー関数を使用した時のthisのコンテキストアロー関数のthisのコンテキストは関数が定義された時点で確定されるよって、上記のsetTimeout内の関数をアロー関数で定義すると、その時点のコンテキストであるsampleとなるconstsamplenameuserageprofilefunctionconsolelogHiMynameisthisnamesetTimeoutgtconsolelogthisageyearsoldsampleprofileHiMynameisuseryearsold教訓クラス式内で関数を使用する時は、挙動が直感的に理解しやすいアロー関数を使用することブラウザ実行の場合。 2021-07-06 20:41:07
js JavaScriptタグが付けられた新着投稿 - Qiita 【メモ】メソッド名や、変数名の命名規則 https://qiita.com/nyappy15th/items/835ee6086391eef7ed12 良い例asyncgetListPromiseltgt悪い例一覧取得は一個だけなので、Userを入れなくてOKasyncgetUserListPromiseltgtちなみに、ライブラリのドキュメントを読んでいてもこのようなルールで記載されており、このメソッド実行すると複数データが返ってくるんだろうなあとか予想ができたりします。 2021-07-06 20:16:59
js JavaScriptタグが付けられた新着投稿 - Qiita TypeScript まとめ https://qiita.com/Islanders-Treasure0969/items/2ac4617b5f4f0e7793b3 型名はbooleanconstsampleboolbooleantrueNumber型数値を扱うためのデータ型。 2021-07-06 20:15:19
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) Pythonで出力する画像データの解像度を上げたい https://teratail.com/questions/348025?rss=all 以下のコードを用いて出力するネットワーク図の画像データの出力を上げたいと考えています。 2021-07-06 20:48:35
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 要素を削除(remove)した後に再び同じセレクタの要素を再取得する方法が分からない。 https://teratail.com/questions/348024?rss=all 要素を削除removeした後に再び同じセレクタの要素を再取得する方法が分からない。 2021-07-06 20:17:51
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) クライアント側で、共有サーバ上に存在するExcelやWord等のファイルを直接アクセス以外の方法で開くことが可能かどうか知りたい。 https://teratail.com/questions/348023?rss=all クライアント側で、共有サーバ上に存在するExcelやWord等のファイルを直接アクセス以外の方法で開くことが可能かどうか知りたい。 2021-07-06 20:02:01
Ruby Rubyタグが付けられた新着投稿 - Qiita 【ざっくり解説】Capistranoでsudoを使いたい https://qiita.com/WAKO_program/items/c3904004110cb3b1e02e 公式のREADMEにも、「sudoを使わない方がスムーズに自動デプロイできるよ」という趣旨の記述があり、やんわりとsudoの使用が非推奨になっています。 2021-07-06 20:48:30
Ruby Rubyタグが付けられた新着投稿 - Qiita _error_messagesによって表示されたメッセージを分かりやすく色で囲む https://qiita.com/N396184501/items/0281e1e4409b939b8312 errormessagesによって表示されたメッセージを分かりやすく色で囲むはじめにこのように投稿に失敗した時にエラーメッセージが出るようにしました。 2021-07-06 20:19:04
Ruby Rubyタグが付けられた新着投稿 - Qiita 【メモ】メソッド名や、変数名の命名規則 https://qiita.com/nyappy15th/items/835ee6086391eef7ed12 良い例asyncgetListPromiseltgt悪い例一覧取得は一個だけなので、Userを入れなくてOKasyncgetUserListPromiseltgtちなみに、ライブラリのドキュメントを読んでいてもこのようなルールで記載されており、このメソッド実行すると複数データが返ってくるんだろうなあとか予想ができたりします。 2021-07-06 20:16:59
Docker dockerタグが付けられた新着投稿 - Qiita 1コマンドで Django on Docker を構築する(4) https://qiita.com/robozushi10/items/0e326d52fa80eca489c8 2021-07-06 20:48:19
Ruby Railsタグが付けられた新着投稿 - Qiita 駆け出しがRailsアプリをHerokuにデプロイするときに躓いたこと https://qiita.com/pekorinko/items/06d0fc0b635d70a5e072 駆け出しがRailsアプリをHerokuにデプロイするときに躓いたことバックエンドエンジニアを目指し、RubyonRailsでGoogleの口コミから信憑性の高い投稿のみを抽出して評価を判定するサービスをポートフォリオとして作成しました。 2021-07-06 20:53:04
Ruby Railsタグが付けられた新着投稿 - Qiita 【ざっくり解説】Capistranoでsudoを使いたい https://qiita.com/WAKO_program/items/c3904004110cb3b1e02e 公式のREADMEにも、「sudoを使わない方がスムーズに自動デプロイできるよ」という趣旨の記述があり、やんわりとsudoの使用が非推奨になっています。 2021-07-06 20:48:30
Ruby Railsタグが付けられた新着投稿 - Qiita _error_messagesによって表示されたメッセージを分かりやすく色で囲む https://qiita.com/N396184501/items/0281e1e4409b939b8312 errormessagesによって表示されたメッセージを分かりやすく色で囲むはじめにこのように投稿に失敗した時にエラーメッセージが出るようにしました。 2021-07-06 20:19:04
海外TECH Ars Technica Evolution of the dad https://arstechnica.com/?p=1778248 species 2021-07-06 11:15:12
海外TECH DEV Community How to execute multiple GraphQL mutations in a transaction using Overblog GraphQL Bundle https://dev.to/bornfightcompany/how-to-execute-multiple-graphql-mutations-in-a-transaction-using-overblog-graphql-bundle-1282 How to execute multiple GraphQL mutations in a transaction using Overblog GraphQL BundleWhen we started working with GraphQL we experienced common issues like N problem error handling etc As our API started growing new challenges occurred They were mostly related to the schema design and how to have a schema that is easy to read and also functional By specification GraphQL allows us to send multiple mutations in a single request and these mutations will be executed in the order in which they were sent GraphQL specification doesn t guarantee us that if some of these mutations fail all others will fail as well In other words GraphQL doesn t specify that all mutations should be executed in the transactions Luckily this can be easily enabled in the Overblog GraphQL Bundle using built in events First in services yaml you need to register the event listener for two events graphql pre executor and graphql post executor services App EventListener GraphQLExecutorListener tags name kernel event listener event graphql pre executor method onPreExecutor name kernel event listener event graphql post executor method onPostExecutor Then in the event listener you have a method for each event In onPreExecutor we start the transaction After mutations are resolved in onPostExecutor we commit the changes if there are no errors or rollback if an error occurred class GraphQLExecutorListener private EntityManagerInterface entityManager public function construct EntityManagerInterface entityManager this gt entityManager entityManager public function onPreExecutor void this gt entityManager gt getConnection gt beginTransaction public function onPostExecutor ExecutorResultEvent event void connection this gt entityManager gt getConnection if connection gt isTransactionActive false throw new LogicException Transaction not active if count event gt getResult gt errors gt while connection gt getTransactionNestingLevel gt connection gt rollback return connection gt commit That s it all mutations should now be executed in the transaction If necessary the event listener can be extended to conditionally enable the transaction for example using a header or some other flag 2021-07-06 11:43:26
海外TECH DEV Community Sample Surveys Application (Kotlin + Spring + RSocket + Vue.js Demo) https://dev.to/antongoncharov/writing-surveys-application-kotlin-spring-rsocket-vue-js-demo-59ba Sample Surveys Application Kotlin Spring RSocket Vue js Demo Recently I started building a repo with boilerplate code to facilitate creation of my future full stack pet projects Despite it s work in progress and always will be as I ll continue to implement new features and tweak existing ones I wanted to share it with the community Check out the GitHub repo I m covering in this post anton goncharov kotlin vue surveys demo Sample Surveys Fullstack Application based on Kotlin Spring WebFlux JPA Bootstrap Vue RSocket SummaryIt s a sample surveys application with the actors of two roles coordinators and respondents Coordinators are allowed to create amp edit polls then review response statistics Respondents have read only view with the only option to submit survey responses One of the key features is that the statistics data is refreshed in real time on a survey stats page It works by using Rsocket and Reactive Streams ConceptsThis demo application showcases the following list of concepts Kotlin and Spring backend API developmentI ve started using Kotlin on new backend projects years ago and it s my first repository to have boilerplate code for full stack apps with Kotlin Here I m using Kotlin in pretty much the same Spring setup as I would use Java Rapid CRUD bootstrapping using Spring Data RESTIt s arguable whether Spring Data REST is a good fit for a production ready project On the other hand it allows a rapid start having full blown API implementation with sorting paging and filtering for given entities Any given controller can be extended with additional handlers or reimplemented from scratch as a separate custom REST endpoint Database migrations with LiquibaseHibernate JPA auto schema creation was used during the development After the first version of the schema had been finalized I generated the Liquibase changelog from JPA entities and disabled ddl auto by Hibernate To populate schema with some initial data predefined users there s sql script on classpath SecurityJWT based authentication with role based access is showcased with tokens issued by the backend ️Such a setup must not be used in production this functionality is only to demonstrate the flow In a real solution use IAM solution like Keycloak or rd party SaaS Reactive flow for live data streamingAfter reading the official guide on Spring Webflux RSocket I got an idea to implement some real time streaming functionality to try Reactive Streams in a demo application setup The survey statistics page is implemented using rsocket js it reads the survey response stream data from a Kotlin Flow that is populated with data from RDBC H reactive ready driver The charts are updated on a survey stats page in real time Building with GradleAs a sidenote I ve never used Gradle before always preferring Maven as a classic tool that makes more sense to me This was an interesting challenge to create something new with Gradle especially writing the build script with Kotlin DSL since there re not many ready to use examples Tech Stack BackendKotlin Spring Boot JPA Data REST Hibernate Security WebFlux H Database with Liquibase database migrationsGradleJUnit FrontendVue js with Vuex Vue router Vue image upload Bootstrap RSocketApexcharts LaunchingTo get it up and running follow the instructions from the GitHub repo Please reach me out if you have any questions or feedback But keep in mind it s a boilerplate code withstanding permanent work in progress Cheers 2021-07-06 11:30:49
Apple AppleInsider - Frontpage News 'M2' chip to arrive in early 2022 in a colorful MacBook Air, says leaker https://appleinsider.com/articles/21/07/06/m2-chip-to-arrive-in-early-2022-in-a-colorful-macbook-air-says-leaker?utm_medium=rss x M x chip to arrive in early in a colorful MacBook Air says leakerApple s M processor will be arriving in early a leaker claims with the first hardware using it apparently set to be some form of MacBook with an updated color scheme So far Apple has released only one chip under the Apple Silicon banner with the M appearing in the first wave of Apple s transitional devices While it is unclear what Apple s next Apple Silicon effort will be one leaker claims a proper second generation chip won t be arriving until Posting to Twitter on Monday iOS developer Dylandkt claims the next generation M is on track to release in the first half of As for the potential product that it will be included within the Twitter account states it will be an upcoming colorful MacBook Air Read more 2021-07-06 11:56:39
海外TECH Engadget The Morning After: The nerve of Audacity https://www.engadget.com/the-morning-after-the-nerve-of-audacity-111535622.html?src=rss The Morning After The nerve of AudacityAudacity is hugely popular audio editing software often used by beginner podcasters but with some powerful features despite its free open source status However recent changes to Audacity s privacy policy have led to accusations that the editing app is now spyware Alongside collecting user data for quot app analytics quot and quot improving our app quot ーtypical stuff ーthe data will also apparently be used for quot legal enforcement quot EngadgetThe policy says it will capture quot data necessary for law enforcement litigation and authorities requests if any quot It may share personal data with quot any competent law enforcement body regulatory government agency court or other third party where we believe disclosure is necessary Yes it s a little vague These privacy policy changes follow Audacity s acquisition by Muse Group back in April The changes also include a ban on under s using Audacity which would violate the license under which the software is currently distributed Data collection was apparently in the planning since Audacity s purchase As some reports have noticed a Github update says the app was supposed to include opt in anonymous analytics data collection handled through Google and Yandex but this was caveated by remarks that it would be quot strictly optional and disabled by default quot It didn t sound as broad as the eventual policy update Talking of Github some users are already calling for a fork of the software creating a new version of the app based on the source code For Audacity owners Muse Group it s a rough start to its newest purchase ーMat SmithFinal Fantasy VII Remake Intergrade s entertaining DLC should also be on PSIt lightly taps into the possibilities of the PS Square EnixFinal Fantasy Remake Intergrade is a little confusing if the name didn t give it away It s Final Fantasy Remake polished up for the PlayStation but it also includes new original content called Intermission This is a two chapter run completely separate to the main game following the once optional character Yuffie arriving into Remake s main locale Midgar Sadly you can only play Intermission with a PS But oh boy it plays like a dream Continue reading Bugatti joins forces with electric hypercar maker RimacIt s a joint venture with Porsche called Bugatti Rimac Bugatti RimacElectric hypercar company Rimac is taking control of Volkswagen s supercar brand Bugatti as part of a joint venture with Porsche which VW owns Bugatti and Rimac will share resources and expertise but remain separate brands with their own production and distribution setups Bugatti will be able to harness Rimac s EV know how and perhaps carry on its legacy of making electric vehicles Rimac meanwhile can tap into the knowledge of Bugatti which makes the second fastest street legal car on the planet the Bugatti Veyron Continue reading A nanofiber membrane could help solve the drinking water crisisThe filter makes sea water drinkable in minutes Korean scientists claim a new desalination technique makes seawater fit to drink in minutes The researchers membrane distillation process resulted in percent salt rejection for a whole month If commercialized they say the solution could help alleviate the drinking water crisis exacerbated by climate change According to the UN more than billion people worldwide are affected by water shortages While scientists have used membrane distillation in the past if the membrane became too wet it was unable to reject the salt This particular solution uses a D membrane and nanotechnology Continue reading Bumble is opening a restaurant to help people date IRL againBringing us back kicking and screaming into the dating game Bumble Float StudioIn New York Bumble is opening a café restaurant wine bar Bumble Brew is scheduled to open for breakfast service on July th with lunch and dinner service starting at the Nolita spot in the coming weeks Along with an seat dining room there will be a cocktail bar patio dining and private dining space The new venture builds on the Bumble Hive pop up community spaces where people can hang out eat and drink and meet others Alas you won t be able to reserve a table direct from the app ーat least not yet Continue reading But wait there s more Astronauts complete China s first ever tandem spacewalkOnePlus Nord N G review A G phone that s predictably averageResearchers retrofit microscopes to take D images of cells in real timePost pandemic gas revival may threaten climate change targetsFacebook Google and Twitter threaten to leave Hong Kong over privacy law changes 2021-07-06 11:15:35
海外ニュース Japan Times latest articles Hakuho and Terunofuji stay perfect on Day 3 in Nagoya https://www.japantimes.co.jp/sports/2021/07/06/sumo/basho-reports/nagoya-basho-2021-day-3/ Hakuho and Terunofuji stay perfect on Day in NagoyaThe convincing win at Dolphins Arena is another positive step for yokozuna Hakuho who will decide whether to continue his storied career based on his 2021-07-06 20:35:54
ニュース BBC News - Home Fully jabbed people to be treated differently - Javid https://www.bbc.co.uk/news/uk-57733276 isolation 2021-07-06 11:10:23
ニュース BBC News - Home Vauxhall UK factory's future secured with plans for electric vehicles https://www.bbc.co.uk/news/business-57726818 vehicles 2021-07-06 11:41:48
ニュース BBC News - Home Shopping getting back to normal, say Sainsbury's and Ocado https://www.bbc.co.uk/news/business-57732525 covid 2021-07-06 11:01:20
ニュース BBC News - Home Doctor denies attempting to murder fellow plastic surgeon https://www.bbc.co.uk/news/uk-england-nottinghamshire-57732882 nottinghamshire 2021-07-06 11:25:12
ニュース BBC News - Home Stockwell Six: Three men have convictions overturned after almost 50 years https://www.bbc.co.uk/news/uk-england-london-57735027 corrupt 2021-07-06 11:33:35
ニュース BBC News - Home Covid in India: Tackling lack of online learning in Delhi's slums https://www.bbc.co.uk/news/newsbeat-57671944 slumsdevanshi 2021-07-06 11:17:32
ニュース BBC News - Home Coronavirus: When can we stop wearing face masks or coverings? https://www.bbc.co.uk/news/health-51205344 england 2021-07-06 11:08:44
ビジネス ダイヤモンド・オンライン - 新着記事 7月12日以降、日経平均株価は上昇トレンドに転換! “絶好の仕込み場”となる今週は、米・長期金利の安定で 上昇余地が拡大する「グロース系ハイテク株」を狙え! - 成り上がり投資術 https://diamond.jp/articles/-/276098 2021-07-06 20:10:00
GCP Google Cloud Platform Japan 公式ブログ ランサムウェアから企業を保護する Chrome OS https://cloud.google.com/blog/ja/products/chrome-enterprise/chrome-os-ransomware/ データとファイルはクラウドに自動的にバックアップされ、復元可能ChromeOSはクラウドファーストのプラットフォームであるため、ランサムウェアの標的になり得るデータはデバイス上にごくわずかしかありません。 2021-07-06 12:00:00
北海道 北海道新聞 中札内のリゾート・フェーリエンドルフに来夏温泉 富裕層向けコテージも今秋開業 https://www.hokkaido-np.co.jp/article/564107/ 起業支援 2021-07-06 20:14:00
北海道 北海道新聞 独の義足選手、五輪出場を要望 マルクス・レーム、IOCに https://www.hokkaido-np.co.jp/article/564104/ 五輪出場 2021-07-06 20:09:00
北海道 北海道新聞 長万部の毛ガニ、今年も即売 まつり中止受け10日 https://www.hokkaido-np.co.jp/article/564086/ 長万部 2021-07-06 20:06:18
北海道 北海道新聞 天皇陛下がワクチン接種 宮内庁発表、1回目 https://www.hokkaido-np.co.jp/article/564103/ 天皇陛下 2021-07-06 20:04:00
ニュース Newsweek 中国のことを最も好きな国はどこ? アメリカのことを最も好きな国はどこ? https://www.newsweekjapan.jp/stories/world/2021/07/post-96649.php 好印象との回答は平均にとどまったが、のシンガポールとのギリシャだけは「中国愛」が突出した。 2021-07-06 20:42:00
仮想通貨 BITPRESS(ビットプレス) ビットポイントジャパン、7/13よりレバレッジ取引にて「イーサリアム(ETH)」の取扱開始 https://bitpress.jp/count2/3_10_12632 取扱 2021-07-06 20:45:37
仮想通貨 BITPRESS(ビットプレス) 【金融庁】FATFによる「暗号資産・暗号資産交換業者に関するFATF基準についての2回目の12ヵ月レビュー報告書」を公表 https://bitpress.jp/count2/3_17_12631 金融庁 2021-07-06 20:40:49
IT 週刊アスキー 「鰹節」をイメージした芋焼酎 スモーキーな燻香でこれは焼酎!? https://weekly.ascii.jp/elem/000/004/061/4061779/ 薩摩酒造 2021-07-06 20:15:00
GCP Cloud Blog JA ランサムウェアから企業を保護する Chrome OS https://cloud.google.com/blog/ja/products/chrome-enterprise/chrome-os-ransomware/ データとファイルはクラウドに自動的にバックアップされ、復元可能ChromeOSはクラウドファーストのプラットフォームであるため、ランサムウェアの標的になり得るデータはデバイス上にごくわずかしかありません。 2021-07-06 12:00:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)