一些偏僻有用的知识点记录(一)

1、<!-- 以下三行是禁止浏览器缓存 -->

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> 
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

2.<input type="button" >,添加class=“hide”,不起作用,type=“text”可以;

3、sort()方法调用比较函数,根据奇偶性质排列数组

function f(a,b){

  var a=a%2;

  var b=b%2;

  if(a==0){  return 1;}

  if(b==0){  return -1;}

}

4、检测数组类型:

方法一:

  var is_array=function(value){

    return Object.prototype.toString.apply(value)==='[object Array]';

}

方法二:

  var is_array=function(value){

    return value&&

      typeof value==='object'&&

      value.constructor===Array&&

      typeof value.length==='number'&&

      typeof value.splice==='function'&&

      !(value.propertyIsEnumerable('length'));

}

5、判断一个数字的最佳方法是使用 isFinite()函数,因为它会删除NaN和Infinity。

6、apply()是函数的一个方法,包括两个参数,第一个是设置绑定给this的值,第二个是包含函数参数的数组

 例:add.apply({},array);

7、闭包:

  闭包包含下列标识符:函数参数(形参变量),arguments属性,局部变量,内部函数名,this(指代闭包函数本身)

  经典闭包示例:

function f(x){
    var a=x;
    var b=function(){
       return a;  
    }
    a++;
    return b;
}  
var c=f(5);
alert(c());    //弹出值6

  没有闭包示例:

function f(x){
  var a=x;
  var b=a;
  a++;
  return b;  
}
var c=f(5);
alert(c);       //返回值为5

  闭包中的变量a是继续引用外部函数定义的局部变量a中的值,直到外部函数f 调用返回。而闭包不会因外部函数环境注销而消失,会始终存在。

 8、prototype扩展类型

  

Function.prototype.method=function(name,func){
    if(!this.prototype[name]){           //这一句是为了确定原来没有同类方法再添加
                  this.prototype[name]=func;      //以下两句是添加这个method方法以后就不用再使用prototype调用了
                  return this;
    }    
  }

//例
Number.method("integer",function(){
    return Math[this<0?"ceil":"floor"](this);
})                            
document.writeIn((-10/3).integer());       //-3

9、模块开发的一般形式:一个定义了私有变量和函数的函数,利用闭包创建可以访问到私有变量和函数的特权函数,最后返回这个特权函数或者把他们存到可访问的地方。

10、如果使用的构造函数(funcA.call(this,2))获取继承且不使用原型链,那么这个继承可能就被破坏。

11、Object与Function都是高度抽象的类型,互为对方的实例。

  Object.prototype是所有父元素的顶层。

12、Object.prototype.a=1

    alert(Object.a);

  var b=new Object;

    alert(b.a);

说明,既可以直接访问Object的prototy属性,也可以实例化以后访问它的属性。

原文地址:https://www.cnblogs.com/kaixin3946/p/5682571.html