Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I tested a HTML w/ the loading of the source code from [^]. It works fine.
Then I loaded the components into another developed page. Once I loaded the JS references, the page displays multiple errors in debugging. Some of the errors are:
Uncaught ReferenceError: Cookie is not defined
Uncaught TypeError: Element.extend is not a function
Is it due to the conflicts between JS references? Thanks if you can help.
Posted

There are no such conflicts between JavaScript references. You are just trying to dereference undefined object. This is a special object specific to JavaScript, distinct from null and all other values. It is used by the runtime system when you declare some variable but don't initialize it. Also, you can assign undefined to any other object at any time.

Consider this:
JavaScript
var Cookie; // undefined
Cookie = undefined; // same as above

function A() { alert("Do something"); }
Cookie = A(); // A did not return anything,
// so Cookie is still undefined

// Now, consider this:
var someOtherVariable = Cookie; // fine!

// But exception if thrown if 
var someOtherVariable = Cookie.a;

I tried it on Mozilla and Chrome, it actually throws TypeError with this error message, but I can imagine that some other browser throws different exception object. Reference errors come in different situations, when some variable (f in my example below) is not even declared:
JavaScript
var someOtherVariable = f;
// ReferenceError: f is not defined

On undefined object (primitive value), please see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined[^],
not to be confused with null: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null[^].

Remaining exception you described is "not a function". Consider this example:
JavaScript
var Element = { }; //value empty object
Element.extend = 42; //fine

Element.extend();
// TypeError:
// Element.extend is not a function

// Another possibility is this:
Element.somethingNotCreated();
// TypeError:
//Element.somethingNotCreated is not a function

I hope the exception message is self-explained.

Please don't ask me what your code did wrong; I don't know and, frankly, don't want to know. You just need to understand the first principles, than you can dig it out.

—SA
 
Share this answer
 
v3
Comments
CPallini 19-Oct-15 16:11pm    
5.
Sergey Alexandrovich Kryukov 19-Oct-15 16:23pm    
Thank you, Carlo.
—SA
Umm, you really should post this question from where you downloaded the code.
Because we really don't know what actually has written in that JS.

Hope I'm clear :)

-KR
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900