Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the outcome in javascript with multiple librarys that use $

Let's pretend this is in the <head> of your html page.

OOPS this was a bit that was missing before...:

<script type="text/javascript" src="/include/js/billys.js"></script>
<script type="text/javascript" src="/include/js/susies.js"></script>
<script type="text/javascript" src="/include/js/marys.js"></script>

Order of the 3 scripts could vary. What would be the outcome?

Billy defines $ as

function $ () {
 return false;
}

Susie defines $ as

function $ () {
 return document.getElementById('body');
}

Mary defines $ as

function $ () {
 alert('I wrote this');
}
like image 701
Doug Chamberlain Avatar asked May 11 '11 19:05

Doug Chamberlain


People also ask

What is a benefit of using JavaScript libraries and frameworks?

JS frameworks and libraries give developers the ability to use prewritten code for common JavaScript functions, and to create their own functions that can then be reused as needed.

Why are there so many different JavaScript libraries?

There are so many frameworks because there can be so many frameworks. JS frameworks are specialised, portable, and often interchangeable. Don't stress about picking the wrong framework – you can always (and almost certainly will) change it later.

What is the purpose of JavaScript libraries?

A JavaScript library is a library of pre-written JavaScript code that allows for easier development of JavaScript-based applications, especially for AJAX and other web-centric technologies.

What are the benefits of integrating JavaScript libraries in your application codes?

The benefit of adopting JavaScript frameworks is that they can improve your code's readability and make it look well-structured. Additionally, the framework will reduce the time required for code development, testing, and debugging.


1 Answers

Whatever is last is the final definition of $

That is why in (for example) jQuery there is noConflict() which lets you use a different variable than $ for jQuery

like image 93
Naftali Avatar answered Sep 21 '22 20:09

Naftali