Skip to content

Commit 7792918

Browse files
committed
optimize process of arg read
1 parent 59c7b5a commit 7792918

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/esl.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,27 @@ var require;
225225
* @param {Function=} factory 创建模块的工厂方法
226226
*/
227227
function define(id, dependencies, factory) {
228-
if (!arguments.length) {
229-
return;
230-
}
231-
232-
if (typeof id !== 'string') {
233-
if (id instanceof Array) {
234-
factory = dependencies;
235-
dependencies = id;
228+
// define(factory)
229+
// define(dependencies, factory)
230+
// define(id, factory)
231+
// define(id, dependencies, factory)
232+
if (factory == null) {
233+
if (dependencies == null) {
234+
factory = id;
235+
id = null;
236236
}
237237
else {
238-
factory = id;
238+
factory = dependencies;
239239
dependencies = null;
240+
if (id instanceof Array) {
241+
dependencies = id;
242+
id = null;
243+
}
240244
}
241-
id = null;
242245
}
243-
else if (!(dependencies instanceof Array)) {
244-
factory = dependencies;
245-
dependencies = null;
246+
247+
if (factory == null) {
248+
return;
246249
}
247250

248251
// 出现window不是疏忽

0 commit comments

Comments
 (0)