JS packaging function 1. Encapsulation hasPubProperty public attribute Object. The prototype. HasPubProperty = function (key) {if ((key) in this &&! this.hasOwnProperty(key)) { return true; } return false; Array.prototype.myPop = function () {let temp = this[this.length-1]; this.length–; return temp; Array.prototype. MyUnique = function () {var obj = {}; for (var i = 0; i < this.length; i++) { if (obj.hasOwnProperty(this[i])) { this.splice(i, 1); i–; } else {obj[this[I]] = this[I]}} copy code 4. Array.prototype. MyPop = function () {let temp = this[this.length-1]; this.length–; return temp; Array.prototype.myPush = function () {var l = ary.length; for (var i = 0; i < l; i++) { this[this.length] = ary[i]; } return this; } copying code 6. Encapsulation myCall method is equivalent to call the Function. The prototype. MyCall = Function myCall (context,… arg) { context = context || window; let a = Symbol(); context[a] = this; let res = contexta; delete context[a]; return res; } copying code 7. Encapsulation myApply method is equivalent to the apply Function. The prototype. MyApply = Function myApply (context, arg) {arg = arg | | []; context = context || window; let a = Symbol(); context[a] = this; let res = contexta; delete context[a]; return res; 8.} copy code encapsulation myBind method is equivalent to the bind Function. The prototype. MyBind = Function (context,… arg) { var _this = this; return function (… Ary) {return _this.apply(context, arg.concat(ary))}} Copy code 9. New function myNew(classN,… arg) { var obj = {}; obj.proto = Person.prototype; var res = Person.call(obj, … arg) return typeof res === ‘object’ ? res : obj; Instanceof function myInstance(temp, classN) {let STR = typeof temp; if (str ! == ‘Object’ && str ! == ‘Function’) return false; var left = temp.proto, right = classN.prototype; while (left) { if (left === right) return true; left = left.proto; Prototype. Plus = function (a) {return this + a; } Number.prototype.minus = function (a) { return this – a; } copying code 12. Enclosed a judging method of data type getType Object. The prototype. GetType = function () {var STR = this. Constructor. The toString (); str = str.slice(9, str.indexOf(‘(‘)); return str.toLowerCase(); } copying code 13. Encapsulation myReverse method is equal to reverse Array. The prototype. MyReverse = function () {for (var I = 0; i < this.length / 2; i++) { let temp = this[i]; this[i] = this[this.length – 1 – i]; this[this.length – 1 – i] = temp; } return this; Array.prototype. Max = function () {return this.sort((a, b) => b-a)[0]; return Math.max(… this); return Math.max.apply(Math,this); Array.prototype.average = function(){return eval(this.join(‘+’))/this.length; }