- (function () {
- Element.prototype.render = function (callback) {
- var me = this;
- if (!me.nodeType || !me.tagName || me.tagName.toLowerCase() !== 'canvas') {
- return;
- }
- var ctx = me.getContext('2d');
- var proxy = {};
- for (var key in ctx) {
- proxy[key] = (function () {
- var ctx = this.ctx;
- var key = this.key;
- var params = [];
- arguments = Array.prototype.slice.apply(arguments);
- arguments.forEach(function (arg) {
- if (typeof arg === 'function') {
- arg = arg.call(me, ctx);
- if (typeof arg === 'object' && !!arg.slice) {
- params = params.concat(arg);
- } else {
- params.push(arg);
- }
- } else {
- params.push(arg);
- }
- });
- if (typeof ctx[key] === 'function') {
- ctx[key].apply(ctx, params);
- } else {
- ctx[key] = params[0];
- }
- return proxy;
- }).bind({
- ctx : ctx,
- key : key
- });
- }
- if (typeof callback === 'function') {
- callback.call(ctx, proxy);
- }
- return ctx;
- };
- })();
- //该片段来自于http://www.codesnippet.cn/detail/1412201514214.html
来源: http://www.codesnippet.cn/detail/1412201514214.html