Javascriptの辞書クラス
例
class MyMap {
constructor() {
this.container = {};
}
display() {
console.log(this.container);
}
hasKey(key) {
return key in this.container;
}
put(key, value) {
this.container[key] = value;
}
delete(key) {
if (this.hasKey(key)) {
delete this.container[key];
return true;
}
return false;
}
get(key) {
return this.hasKey(key) ? this.container[key] : undefined;
}
keys() {
return Object.keys(this.container);
}
values() {
let values = []; for (let key in this.container) {
values.push(this.container[key]);
}
return values;
}
clear() {
this.container = {};
}
forEach(callback) {
for (let prop in this.container) {
// Call the callback as: callback(key, value)
callback(prop, this.container[prop]);
}
}
} -
JavaScriptのcontinueステートメント
継続ステートメントは、特定の条件が発生した場合に1回の反復をジャンプするために使用されます。条件が満たされた場合、その反復はスキップされ、次の反復から続行されます。 以下は、JavaScriptでcontinueステートメントを実装するためのコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=devic
-
JavaScriptのnew.target
new.targetは、関数コンストラクターがnewキーワードを使用して呼び出されたかどうかを実行時に判別できるようにするメタプロパティです。 以下は、JavaScriptのnew.targetのコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=