开发者

javascript function name collision

I have two JavaScript files that contain a jQuery function with the same name $(). 开发者_高级运维

How can I distinguish between the two identically named functions?


Short answer: You can't. All includes js files live in the same namespace.


Rename one.

$ = typeof $ !== 'function' ? $ : $foo;


Try using a namespace for each project you work on. For instance, instead of writing a function called dosomething(), call it myproject.dosomething()

That way, it is project specific and you will avoid having two identically named functions, even if you are including files you did not develop yourself.


Perhaps you want Using jQuery with Other Libraries, but I can't tell exactly what your problem is from the question. Perhaps you could include some sample code of the problem you're having?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜