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();
})
난 그냥 효과 ('상자')의 속기를 실행하는 동일한 결과를 얻을 어떻게 위의 코드는 실행되지 않습니다
실행().
가 만족 인 경우 답을 동의하거나, 함께 환호 도움이 필요 더 이상 문제를 강조하세요 :) –