私はTerminalクラスのoutput()関数にアクセスしたい無名関数を持つ関数コンストラクタを持つTerminalという名前のクラスを持っています。これどうやってするの?ファンクションinクラス
this.output()を使用するとエラーが発生します。 this
に等しいthat
:
class Terminal
{
constructor(contentID, inputID, options)
{
if (!contentID || !inputID || !options)
{
return false;
}
this.cid = contentID;
this.iid = inputID;
if (!options['pcName'] || !options['username'])
{
return false;
}
this.pcname = (options['pcName'].replace('<', '<')).replace('>', '&rt;');
this.username = options['username'];
this.version = '0.01';
// commands
this.commandsList = [];
this.commandsList['whoami'] = function(){ Terminal.output('lol') };
console.log('terminal.js version ' + this.version + ' initializing');
this.output('ja', true);
this.output('whoami', true);
this.output('i dont know bro', false, 'whoami');
}
output (text, prefix, cmdName) // cmdName is matters only when prefix is false
{
if (this.cid && text)
{
if (prefix == true)
{
text = this.username + '@' + this.pcname + ':~$ ' + text;
}
else if (cmdName)
{
text = cmdName + ': ' + text;
}
var con = document.getElementById(this.cid);
con.innerHTML = con.innerHTML + text + '<br>';
}
}
makeCommand (cmd)
{
if (cmd && cmd != '' && this.commandsList)
{
cmd = (cmd.replace('<', '<')).replace('>', '&rt;');
if (this.commandsList[cmd])
{
console.log('Executing ' + cmd);
this.commandsList[cmd]();
}
}
}
}
this.output()、出力のように「これ」機能に特異的に結合することができます()とTerminal.output() - 結果なし。 – Dante383
私たちにコード – Ivan
を表示するhttp://pastebin.com/95seeX7xそれは、私が意味する混乱しているが匿名の機能は、21行目で、それは54で呼び出されます。 – Dante383