I am not very good at javascript which is why I rely on jquery plugins for most of what I do. However many times two of them conflict with each other and one/both of them stop working properly or don't work at all. So I unminify one of them and rename all/most of the variables and functions in it. Sometimes this works and sometimes it doesn't and depending on the size of the file it could take me hours to do so which is very intruding and tiresome. Is there a more easy and practical shortcut method to do this?
Asked
Active
Viewed 42 times
0
-
Please post your code where the problem occured. – Wais Kamal Dec 24 '16 at 08:35
-
an entire jquery plugin? – Usman Sikander Dec 24 '16 at 08:37
-
I would suggest looking for a better plugin, if this is a problem. Most well-known / good plugins for jQuery works fine together with other plugins, and there is no overlap / cross-contamination. – junkfoodjunkie Dec 24 '16 at 09:54
1 Answers
1
You should use module pattern in its most basic form if plugins' authors weren't aware of it:
(function($) {
// Define here the whole plugin code
// Functions create scopes. Anything declared witihn
// this immediately-invoked function expression (IIFE)
// will be local and it won't conflict with other plugins
}(jQuery);
See this other Q&A to understand what's an IIFE: What is the (function() { } )() construct in JavaScript?
Also, this Q&A might be of interest for you: why module pattern?

Community
- 1
- 1

Matías Fidemraizer
- 63,804
- 18
- 124
- 206
-
dont mind my ametureness in asking but how do i give this function a name and declare it – Usman Sikander Dec 24 '16 at 08:54
-
@UsmanSikander hahaha, no problem ;) It's intended to don't own a name. It's an anonymous function. You invoke once it has been defined. – Matías Fidemraizer Dec 24 '16 at 08:55
-
thanks bro p.s if you don't mind me asking how professional are you in javascript. Are you like a web developer with a degree/diploma or did you also just take some w3schools tortorials like I did – Usman Sikander Dec 24 '16 at 10:48
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131405/discussion-between-usman-sikander-and-matias-fidemraizer). – Usman Sikander Dec 24 '16 at 10:50