TypeScript [edit]

TypeScript とは[edit]

プロパティ(変数)一覧 [edit]

let keyArray = Object.keys(user);
keyArray.forEach(function(element){
 console.log(user[element]);
});
for (const key in obj) {
  console.log(String(key) + " -> " + obj[key]);
}

メソッド(関数)一覧 [edit]

const getMethods = (obj: object): string[] => {
 const getOwnMethods = (obj: object) =>
   Object.entries(Object.getOwnPropertyDescriptors(obj))
     .filter(([name, {value}]) => typeof value === 'function' && name !== 'constructor')
     .map(([name]) => name)
 const _getMethods = (o: object, methods: string[]): string[] =>
   o === Object.prototype ? methods : _getMethods(Object.getPrototypeOf(o), methods.concat(getOwnMethods(o)))
 return _getMethods(obj, [])
}

上記をまとめた関数 [edit]

function disp_obj(obj: object) {
   const getMethods = (obj: object): string[] => {
       const getOwnMethods = (obj: object) =>
       Object.entries(Object.getOwnPropertyDescriptors(obj))
           .filter(([name, {value}]) => typeof value === 'function' && name !== 'constructor')
           .map(([name]) => name)
       const _getMethods = (o: object, methods: string[]): string[] =>
       o === Object.prototype ? methods : _getMethods(Object.getPrototypeOf(o), methods.concat(getOwnMethods(o)))
       return _getMethods(obj, [])
   }

   console.log("+++++++++++++++++++++++++++++++++++");
   for (const key in obj) {
     console.log(String(key) + " -> " + obj[key]);
   }
   console.log("===================================");
   console.log(getMethods(obj));
   console.log("+++++++++++++++++++++++++++++++++++");
}

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