このコードスニペットは何をしますか?その実用的な使用法は何ですか?私はこのコードを書かなかった。私はここでそれを見つけた:https://gist.github.com/anonymous/7407896すぐに呼び出されたオブジェクトリテラル
!{
//convenience methods here for create and expose via this
create: function(options){
//constructor logic here
var created = Object.create(this.fn);
var args = [].slice.call(arguments);
this.plugins.forEach(function(plugin){
plugin.apply(created, args);
});
return created;
},
fn:{//prototype methods here
},
expose:function(NameSpace, window, document, plugins){
window[NameSpace] = this;//This can be tweaked for whatever
this.document = document;
this.plugins = plugins;
}
}.expose("LibraryNamespace", window, document, []);
私は暴露のモジュールのパターンのようなものをやってよりも良くある上記の方法を知って興味があります。また、私はcreate関数のメカニズムについても不明です。誰かが渡されたプロトタイプに基づいてオブジェクトを作成するプロセスを通して私を歩くことができますか?
'create'はどのように使われますか? – Bergi
'expose'メソッドは、露出と初期化を混同しています。 – Bergi