私はelFinderに似たファイルマネージャーフレームワークに取り組んでいます。現在のコードは正常に機能しますが、見栄えを良くしてチェーンを追加したいと思います(チェーンかデコレータパターンかはわかりません)。
これが私がやりたいことのサンプルです:
function UI() {}
UI.prototype.folders = function(){
return [];
}
UI.prototype.folders.prototype.getSelectedFolder = function(){
return {};
}
を呼び出すUI.folders()
と、フォルダオブジェクトの配列が返されます。したがって、電話をかけるUI.folders()
と、次のようなものが得られます。
[
Object { name="folder1", selected=false },
Object { name="folder2", selected=false },
Object { name="folder3", selected=true }
]
そして、呼び出すUI.folders().getSelectedFolder()
と、からの結果がフィルタリングされUI.folders()
、次が返されます。
Object { name="folder3", selected=true }
これは可能ですか?この場合、「連鎖」と言うのは正しいですか、それとも「装飾的なパターン」ですか?
そうでない場合-それを行うための別のより適切な方法はありますか?
どんな助けでも本当にありがたいです!