本人初学JS,还望指教
刚才看jquery的API removeClass方法 可以接受一个函数
.removeClass( function(index, class) )但是用class作为方法的型参不是会出错的么
考虑到class是JS保留字,但int,long也是保留字,定义个var int = 1; 都是没错的
定义 var class = 1;就是错误的.具体的规范是什么? 有木有这方面的文章介绍

解决方案 »

  1.   

    class 关键字吧  尽量避开这些关键字
      

  2.   

    ECMAScript 关键字
    http://www.w3school.com.cn/js/pro_js_keywords.aspECMAScript 保留字
    http://www.w3school.com.cn/js/pro_js_reservedwords.aspclass是保留字
      

  3.   

    保留词
    break  delete  function  return  typeof
    case  do  if  switch  var
    catch  else  in  this  void
    continue  false  instanceof  throw  while
    debugger  finally  new  true  with
    default  for  null  try    
    为将来保留的词
    abstract  double  goto  native  static
    boolean  enum  implements  package  super
    byte  export  import  private  synchronized
    char  extends  int  protected  throws
    class  final  interface  public  transient
    const  float  long  short  volatile
    int现在还不是保留字吧
     
      

  4.   

    .removeClass( function(index, class) )
    class指的是css的class名称
    如果
    <style type="text/css">
     .font{
      font-size:20px;
      color:#333;
     }
    此时class 名字为font。
    .removeClass( "font");
      

  5.   


    行吧, 但是我还是想问,同为保留字class换成int为什么就没问题呢
      

  6.   


    $('.foo.bar20').addClass('baz20');
    $('.foo.bar40').addClass('baz40');// ... later// reset all$(.foo).removeClass (function (index, class) {
    var matches = class.match (/baz\d+/g) || [];
    return (matches.join (' '));
    });
    这是jquery官网的代码
      

  7.   

    break case catch continue default
    delete do else finally for
    function if in instanceof new
    return switch this throw try
    typeof var void while with
    以上是js中的关键字, 不能在代码中用作对象名, 否则会报编译错误;abstract boolean byte char class
    const debugger double enum export
    extends final float goto implements
    import int interface long native
    package private protected public short
    static super synchronized throws transient
    volatile
    以上是js中的“保留字”, 顾名思义, 就是说目前可以用作对象名, 但是在未来的js版本中它们也可能会成为关键字。抄来的
      

  8.   

    http://www.aptana.com/reference/html/api/JSKeywords.index.html
    aptana上列出的关键字
    JavaScript Keywords Index