5

I have two JavaScript files that contain a jQuery function with the same name $().

How can I distinguish between the two identically named functions?

Keerthi
  • 525
  • 8
  • 14
user368038
  • 265
  • 1
  • 5
  • 16

4 Answers4

2

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

Tim Büthe
  • 62,884
  • 17
  • 92
  • 129
  • Also, everyone sticks simple method names in $.fn. So something like '$.fn.fileupload', '$.fn.colorpicker', '$.fn.autocomplete', or '$.fn.scrollto' will probably already be defined by some library. – Triynko Dec 07 '15 at 20:53
  • @Triynko: Sure, that is jQuery's extension point and you're supposed to do so. However, I think this isn't the question here. Besides, you can get name conflicts there too, if you for example use two plugins that asign the same name there. – Tim Büthe Dec 08 '15 at 09:07
1

Rename one.

$ = typeof $ !== 'function' ? $ : $foo;
Michael Sparks
  • 645
  • 3
  • 10
1

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.

Philip Schweiger
  • 2,714
  • 1
  • 18
  • 27
0

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?

Douglas
  • 36,802
  • 9
  • 76
  • 89
  • $(dmatrix.MatrixData.Combination).each(function(index) {..} these is the function call dmatrix.MatrixData.Combination is a collection i have jquery-1.4.2.js and dotnetnuke .js in my app – user368038 Jun 16 '10 at 08:59