TypeScript †[edit]
TypeScript とは[edit]
- JavaScript にクラスの概念や,(コンパイラ風)文法チェックを無理やり導入したもの.
- そのため,JavaScriptに比べて制限がかかる.
- 最終的に,JavaScriptに変換されて実行される.
プロパティ(変数)一覧 †[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("+++++++++++++++++++++++++++++++++++");
}