面试题

<script type="text/javascript">
 function Target(type) {
  this.type = type;
  this.arr = [];
 }

 Target.prototype = {
  match: function(type, callback) {
   this.arr.push(type);

   this.target = type;
   if (this.type === this.target) {
    callback(this.target);
   }
   return this;
  },

  others: function(target) {
   // console.log('arr: %o', this.arr,  this.arr.indexOf(target));
  if (this.arr.indexOf(this.type) == -1) {
      return console.log(target)
  }
  }
 }

 function target(type) {
  return new Target(type);
 }


 target(10)
  .match(1, console.log)
  .match(2, console.log)
  .others(10);

</script>

 

posted @ 2018-02-27 08:56  赛赛大人  阅读(75)  评论(0编辑  收藏  举报