1

I am trying to clone an object using

var newObject = jQuery.extend(true, {}, oldObject);

as per John Resig's answer to What is the most efficient way to deep clone an object in JavaScript? .

All the information I can find on using libraries in javascript only show how to use a library within an html file... as in:

<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>

My code is in a .js file and i get the error that jQuery is not defined. How do I use jQuery within my .js file?

EDIT: I'm running this code in a server.js file on a node server. The server.js has an event handler that gives back the index.html file upon getting the "/" url. So the server.js file isn't included in the index.html file and therefore including jquery in the html file doesn't help me, if my understanding is correct.

Community
  • 1
  • 1
SUCHANOOB
  • 23
  • 3
  • possible duplicate of [How to include a JavaScript file in another JavaScript file?](http://stackoverflow.com/questions/950087/how-to-include-a-javascript-file-in-another-javascript-file) – Victory Apr 07 '14 at 04:17

1 Answers1

0

You can't include it or link to it from within your .js file. You have to include it on the HTML page (<script src="/path/to/jquery"></script>), before you include your .js file.

Technically you could just copy and paste the jquery code above the code in your .js file, but it is usually a better idea to just include it on the page to avoid conflicts.

ElGavilan
  • 6,610
  • 16
  • 27
  • 36