• 追加された行はこの色です。
  • 削除された行はこの色です。
#author("2019-10-09T14:10:54+09:00","default:ryuichi","ryuichi")
* 型の比較 [#q32ed9ef]
#author("2020-06-13T22:41:29+09:00","default:ryuichi","ryuichi")
* 型の比較 - instanceof typeof [#x69a8182]

** 型を確かめる - instanceof [#u1587977]

 import { Bear } from './bear.model'; 
 class Book {
 }
 
 const bear = new Bear(3);
 const book = new Book();
 
 if (bear instanceof Bear) {
     console.log("OK1");
 if (book instanceof Book) {
     console.log("OK");
 }
 
 // if (typeof bear === Bear) { // typeofでは動かない
 //     console.log("OK2");
 if (typeof book == "object") {
     console.log("OK");
 }
 
 // if (typeof book == "Book") {
 //     console.log("OK");
 // }
 // 
 // typeofはプリミティブ型しか返さない



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS