TypeError: Cannot read property "0" from undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 11:53 AM
Hello,
I am working on a code in which I have called a function1 from function2 within same script include.
Earlier I had written it as :
function2 : function(){
function1 (type,name);
}
Output : Code was not working and was getting error as 'ReferenceError: "function1" is not defined.'
Now I have replaced it as (it was hit and traial):
function2 : function(){
//var obj = new XYZ(); //Script include which I am currently working in and this line is commented
obj. function1 (type,name);
}
Output : Code is working but getting error as 'TypeError: Cannot read property "0" from undefined'
Now, even though the code is working but ideally defining as obj.function1() is incorrect as far as my understanding.
So why did it work and also what does the error mean and how can I remove it.
Also even though the function was defined in 1st attempt, why did it throw as not defined.
Thank you.
- Labels:
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 12:04 PM
can you try using this.functionname() instead of obj.functionname()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 12:05 PM
Hi Rachael,
In script include we usually call the different method using this keyword say for example you have a method name function1 and other method as function2 then you have to write like this:
function1 : function(){
this.function2();
},
function2:function(){
//code
},
Please mark answer correct or helpful if it works fine.
Thanks,
Cb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 06:09 AM
Hi Rachael,
I just wanted to check if you got the answer?
If it is resolved by my answer then can you please mark my answer as correct and helpful so that others can be befitted with the solution in future.
Thanks,
CB