Skip to content

Instantly share code, notes, and snippets.

@redbluish
Created November 27, 2013 08:59
Show Gist options
  • Select an option

  • Save redbluish/7672714 to your computer and use it in GitHub Desktop.

Select an option

Save redbluish/7672714 to your computer and use it in GitHub Desktop.
dynamic generate methods.
;(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);
@zhoumengkang
Copy link

;(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