Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript issue with object type in IE

There is a strange issue with IE-8 I have ! I have 3 javascript files in my project

This is my code in first JSFile1:

function validate(p){
  return p !== undefined;
}

and this is my second file JSFile2:

function myfunc(p){
  if(validate(p.class) && validate(p.n1) && validate(p.n2))
     alert(p.class + ' ' + p.n1*p.n2);//    doSomething
}

and this is the last js file: JSFile3:

var virtual={
  class:860,
  another:'good',
  type:'ask'
};
// here is function
$(document).ready(function(){
  myfunc({
    class:'my value',
    n1:3,
    n2:5
  });
});

In firefox I have no trouble but in IE-8 log shows me these errors :

Expected identifier
string or number Expected identifier
like image 734
Omid Avatar asked Aug 31 '26 18:08

Omid


1 Answers

class is a reserved keyword, you have to quote it.

var virtual={
  'class':860,
  another:'good',
  type:'ask'
};
// here is function
$(document).ready(function(){
  myfunc({
    'class':'my value',
    n1:3,
    n2:5
  });
});
like image 70
OneOfOne Avatar answered Sep 02 '26 09:09

OneOfOne