javascript学习笔记

快速排序算法

var quicksort=function(arr){
 if (arr.length <= 1) { return arr; }
var index = Math.floor(arr.length /2);
var indexValue = arr.splice(index,1)[0];
var left=[];
var right=[];
for(var i=0;i<arr.length;i++){
if (arr[i]<indexValue ){ left.push(arr[i]);}
if (arr[i]>=indexValue ){ right.push(arr[i]);}
}
return quicksort(left).concat([indexValue],quicksort(right));
}

 构造函数的继承  

function extend(Child, Parent) { //YUI采用的方法

    var F = function(){};
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
    Child.uber = Parent.prototype;
  }

拷贝继续

function extend2(Child, Parent) {
    var p = Parent.prototype;
    var c = Child.prototype;
    for (var i in p) {
      c[i] = p[i];
      }
    c.uber = p;
  }

  非构造函数的继承 object()

function object(o) {
    function F() {}
    F.prototype = o;
    return new F();
  }

深拷贝 jquery使用的方法

function deepCopy(p, c) {
    var c = c || {};
    for (var i in p) {
      if (typeof p[i] === 'object') {
        c[i] = (p[i].constructor === Array) ? [] : {};
        deepCopy(p[i], c[i]);
      } else {
         c[i] = p[i];
      }
    }
    return c;
  }
原文地址:https://www.cnblogs.com/henshui/p/4812848.html