Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onload && onload.apply 类似的检验不严谨导致使用不便的问题 #46

Open
menglexing opened this issue Feb 6, 2017 · 1 comment

Comments

@menglexing
Copy link

menglexing commented Feb 6, 2017

示例:

function getXXX (callback) {
    require.async('xxx', callback)
}

// 预加载
// 这样的使用方式,会导致传递给 require.async 的callback 会是 jq的event对象
// 因为modJS内部的判断 onload && onload.apply... 不够严谨进而导致报错
$(window).on('load', getXXX)    

// 主动加载
$('#showXXX').on('click', function(e){
    getXXX(function(xxx){
        xxx.show()
    })
})

我不得已给getXXX加上了参数校验:

function getXXX (callback) {
    if (typeof callback !== 'function') callback = function () {};

    require.async('xxx', callback)
}
@oxUnd
Copy link
Contributor

oxUnd commented Feb 6, 2017

可以提个 PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants