一、myPush()//myPush() 数组入栈Array.prototype.myPush = function(){ var L = this.length; for(var i = L ; i < L + arguments.length ; i++){ this[i] = arguments[i - L]; } return this.length;}二、myPop()//Mypop() 数组出栈Array.prototype.myPop = function(){ if (this.length == 0) { return undefined; } var last = this[this.length-1]; this.length = this.length-1; return last;}三、myUnshitf()//myUnshift 数组入队Array.prototype.myUnshift = function(){ var L = this.length; for(var i = L + arguments.length - 1 ; i >= 0 ; i--){ if(i > arguments.length - 1){ this[i] = this[i - arguments.length]; }else{ this[i] = arguments[i]; } } return this.length;}四、myShitf()//myShift()数组出队Array.prototype.myShift = function(){ if (this.length == 0) { return undefined; } var firstElement = this[0]; for(var i = 1 ; i < this.length ; i++){ this[i-1] = this[i]; } this.length = this.length-1; return firstElement;}纯手写,如有不善,请指正 ^_^
