class Hoge {
constructor(a, b) {
this.typename = "Hoge";
this.menberA = 0;
this.menberB = 0;
if(b != null) {
this.menberA = a;
this.menberB = b;
}
}
isHoge(){
if(this.typname != null) return (this.typename === "Hoge");
return false;
//return ((this.typname != null) ? (this.typename === "Hoge") : false); でもいいかも
}
hage(c) {
this.menberA = c;
};
}
//オーバーライドして振る舞いを変更
Hoge.prototype.hage = function (c) {
this.menberB = c;
}
//テキストコマンド実行クラス
class CommandProc {
constructor() {
this.typename = "CommandProc";
this.cmdnum = 0;
this.cmdline = new Array();
this.cmdstr = ['null', 'CMD_A', 'CMD_B'];
this.cmdelm;
return this;
}
init(){
//コマンド入力のテキストボックス
this.cmdelm = document.getElementById('TXT_CMD');
}
analyzecmdline(str){
var work = str;
this.cmdline = new Array();
work = work.replace( /\t/g,"");
work = work.replace( /\s/g,"");
this.cmdline = work.split(",");
}
checkcmd(){
this.cmdnum = 0;
var str = this.cmdelm.value;
this.analyzecmdline(str);
var i;
for(i = 0; i < this.cmdstr.length; i++){
if(this.cmdline[0] == this.cmdstr[i]){
this.cmdnum = i;
return;
}
}
}
done(){
this.checkcmd();
switch(this.cmdstr[this.cmdnum]){
case 'CMD_A':
break;
case 'CMD_B':
break;
default:
}
}
passivebeforedraw(){
switch(this.cmdstr[this.cmdnum]){
case 'CMD_A':
break;
case 'CMD_B':
break;
default:
}
}
passiveafterdraw(){
switch(this.cmdstr[this.cmdnum]){
case 'CMD_A':
break;
case 'CMD_B':
break;
default:
}
}
click(){
switch(this.cmdstr[this.cmdnum]){
case 'CMD_A':
break;
case 'CMD_B':
break;
default:
}
}
}
### SCRIPT #########
//テキストコマンド実行クラス
class CommandProc {
constructor() {
this.typename = "CommandProc";
this.cmdnum = 0;
this.cmdline = new Array();
this.cmdstr = ['null', 'CMD_A', 'CMD_B'];
this.cmdelm;
return this;
}
init(){
//コマンド入力のテキストボックス
this.cmdelm = document.getElementById('TXT_CMD');
}
analyzecmdline(str){
var work = str;
this.cmdline = new Array();
work = work.replace( /\t/g,"");
work = work.replace( /\s/g,"");
this.cmdline = work.split(",");
}
checkcmd(){
this.cmdnum = 0;
var str = this.cmdelm.value;
this.analyzecmdline(str);
var i;
for(i = 0; i < this.cmdstr.length; i++){
if(this.cmdline[0] == this.cmdstr[i]){
this.cmdnum = i;
return;
}
}
}
done(){
this.checkcmd();
switch(this.cmdstr[this.cmdnum]){
case 'CMD_A':
var str = "";
var i;
if(1 < this.cmdline.length) str += this.cmdline[1];
for(i = 2; i < this.cmdline.length; i++) str += ", " + this.cmdline[i];
alert("CMD_A : " + str);
break;
case 'CMD_B':
var str = "";
var i;
if(1 < this.cmdline.length) str += this.cmdline[1];
for(i = 2; i < this.cmdline.length; i++) str += ", " + this.cmdline[i];
alert("CMD_B : " + str);
break;
default:
}
}
}
var CMDP = new CommandProc();
function onDone(){
CMDP.done();
}
### HTML #########
<body ... onload="CMDP.init();">
...
コマンド入力('CMD_A, ...', 'CMD_B, ...')<br>
<input type="text" id="TXT_CMD" name="TXT_CMD" size='80' value=''><br>
<input type="button" id="BTN_DONE" name="BTN_DONE" value='Done' onclick='onDone();'><br>
...