Created
November 27, 2013 08:59
-
-
Save redbluish/7672714 to your computer and use it in GitHub Desktop.
dynamic generate methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function (window, undefined) { | |
// [es5-shim.min.js](http://tinyurl.com/omk7rjt) | |
'use strict'; | |
'11||111||2||2||3||4||2||3||3||4||5||5||3||4||5||6||5||6||4||4||4||4||4||4||4||4||4||5||6||6' | |
.split('||') | |
.reduce(function (result, item, index) { | |
index % 6 === 0 ? result.push([item]) : result[result.length - 1].push(item); | |
return result; | |
}, []) | |
.forEach(function (answer, index, self) { | |
window['loadDbData' + (index + 1)] = function () { | |
return answer; | |
}; | |
window['qna' + (index + 1)] = function (replacement) { | |
this.parent.doHomework(uid, cname, { | |
'0': (function ( me ) { | |
me.splice(index, 1, replacement); | |
return me.join('||'); | |
})( self.slice(0) ) | |
}); | |
}; | |
}); | |
}).call(this, this); |
;(function (window, undefined) {
window.parent.getAnswer(uid,cname).split('||')
.reduce(function (result, item, index) {
index % 6 === 0 ? result.push([item]) : result[result.length - 1].push(item);
return result;
}, [])
.forEach(function (answer, index, self) {
window['loadDbData' + (index + 1)] = function () {
//top.console.log(answer.join("||"));
return answer.join("||");
};
window['qna' + (index + 1)] = function (replacement) {
this.parent.doHomework(uid, cname, {
'0': (function ( me ) {
me.splice(index, 1, replacement);
//top.console.log(me.join('||'));
return me.join('||');
})( self.slice(0) )
});
};
});
}).call(this, this);
把上面的代码换成了下面的,顿时觉得高端大气上档次多了!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
哈哈哈哈!这么快!应该把我的源代码贴上来。