HighCharts源码学习---扩展函数wrap和扩展对象 extendClass
来源:互联网 发布:java连接zookeeper报错 编辑:程序博客网 时间:2024/06/07 05:55
Highcharts.wrap在原函数的基础上扩展原函数
/** * Wrap a method with extended functionality, preserving the original function * @param {Object} obj The context object that the method belongs to * @param {String} method The name of the method to extend * @param {Function} func A wrapper function callback. This function is called with the same arguments * as the original function, except that the original function is unshifted and passed as the first * argument. */
var wrap = Highcharts.wrap = function (obj, method, func) { //备份原函数 var proceed = obj[method]; obj[method] = function() { //拷贝一份实参 var args = Array.prototype.slice.call(arguments); //将原函数的引用放到第一个入参 args.unshift(proceed); //保持上下文调用func func.call(this, args); }
}利用wrap重新封装parseInt()
wrap(window, parseInt, function(proceed, str, scale) { if(typeof str === 'number') return proceed.call(this, str); var hexChars = 'abcdef', decChars = '9'; var hasHex = false,hasDec = false,i = 0, len = str.length; if(!scale) { if(str.charAt(0) === '0') { if(str.charAt(1) === 'x') { return proceed.call(this, str, 16); } else { for(i = 0;i < len; i++) { var char = str.charAt(i).toLowerCase(); if(hexChars.indexOf(char) > -1) hasHex = true; if(decChars.indexOf(char) > -1) hasDec = true; } } if(hasHex) { return procced.call(this, str, 16); }else if(hasDec) { return procced.call(this, str, 10); } else { return procced.call(this, str, 8); } } return procced.call(this, str, 10); } })
Highcharts扩展原型对象
/** * Extend a prototyped class by new members * @param {Object} parent * @param {Object} members */ function extendClass(Parent, members) { var object = function () { }; object.prototype = new Parent(); extend(object.prototype, members); return object; }
0 0
- HighCharts源码学习---扩展函数wrap和扩展对象 extendClass
- jQuery源码学习笔记:扩展工具函数
- ES6入门(数组扩展,函数扩展,对象扩展,Symbol,数据结构)
- jQuery源码学习(版本1.11)-扩展工具函数
- ES6--对象、函数的扩展
- kotlin的扩展函数和扩展属性
- kotlin学习day11:扩展函数
- 对象扩展
- 对象扩展
- C++学习笔记--函数参数扩展和占位参数
- Dom对象扩展和JSC内置对象
- js对象深拷贝和对象扩展
- 扩展函数
- 扩展函数
- 函数扩展
- Javascript 类级别扩展和对象级别扩展的区别
- Kotlin编程之扩展属性和扩展伴生对象
- javascript 扩展Function对象 获取函数名称
- linux command - sort
- method="get/post",两种方式的区别
- Linux信号通讯编程
- win7安装oracle
- (浮点数及整数)高精度乘除法
- HighCharts源码学习---扩展函数wrap和扩展对象 extendClass
- S3C2440存储控制器和MMU浅析
- DP---求给定矩阵中最大正方形的维度
- git 的基本用法
- 插入排序
- 设计模式六大原则(4):接口隔离原则
- 文章标题
- 【重走普及路】【分治】【经典算法】快速幂
- 贪吃蛇详解Windows编程(一)