1
私は古いJavascriptファイルの1つをrequireJSと互換性のあるものに移植します。これは以前のコードの様子です。このモジュールをrequireJSと互換性を持たせるには
// effect.js
(function(exports){
// shorthand
exports.effect = function(selector) {
return new Effect(selector);
};
// init
exports.Effect = function(selector){
this.target = document.getElementById(selector);
};
Effect.prototype.run = function(){
alert('halo');
};
})(this);
//invoke it with
effect('box').run();
はrequireJSと互換性を持たせるためにしようとしました:
// effect.js
define(function(exports){
// Shorthand
exports.effect = function(selector) {
return new Effect(selector);
};
// init
exports.Effect = function(selector){
alert('halo');
this.target = document.getElementById(selector);
};
Effect.prototype.run = function(){
alert('halo');
};
}
// require js
require([
'effect.js'
],function(Effect){
effect('box').run();
})
上記のコードはどのように私は効果(「箱」)の短縮を実行すると同じ結果を得るか、実行されません実行します。 ()。
を、それは満足のいくものであった場合は答えを受け入れるか、またはあなたが助けが必要な任意の更なる問題を強調表示し、歓声してください:) –