面试题
<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>