Ashish Ashish - 2 months ago 16
Javascript Question

websocket.js:120 Uncaught ReferenceError: insideFun is not defined when I added function inside the function

I am getting coordinates data via Web Socket.

ws.onmessage = newmessage;
function newmessage (event) {
var mySpan = document.getElementById("messageGoesHere");
var mySpan2 = document.getElementById("messageGoesHere2");
var str =;

After splitting the coordinates I am adding that values into draw function

var array = str.split('|');
mySpan.innerHTML = parseInt(array[2]);
mySpan2.innerHTML = parseInt(array[3]);
draw(parseInt(array[2]), parseInt(array[3]));
else if((array[1].localeCompare('con'))==0)
checkData(parseInt(array[2]), parseInt(array[3]), parseInt(array[4]))

Now I want use the drawDrid function inside the draw function, if it is possible or kindly suggest me some another solution.

function draw(a, b){
console.log("a :" +a+"b :"+b);
ctx.fillStyle = "#000";
a = a * gridBoxLength;
b = b * gridBoxLength;
ctx.fillRect(a, b, gridBoxLength, gridBoxLength);
function checkData(x, y, z){
console.log("x :"+x+"y :"+y+"z :"+z);


Try this code , maybe this will help you. If you want to use a function inside the function you have to window for accessing data outside the function and this is the only way to access outside function data.


window.newFunction =  function (a,b,c,d,e)
 { = [a,b,c,d,e];