灏天阁

访问者模式

· Yin灏
/**
 * 对象访问器
 */
// 访问器
var Visitor = (function () {
  return {
    // 截取
    splice: function () {
      var args = Array.prototype.splice.call(arguments, 1);
      return Array.prototype.splice.apply(arguments[0], args);
    },
    // 追加数据方法
    push: function () {
      var len = arguments[0].length || 0;
      var args = this.splice(arguments, 1);
      arguments[0].length = len + arguments.length - 1;
      return Array.prototype.push.apply(arguments[0], args);
    },
    // 弹出最后一次添加的元素
    pop: function () {
      return Array.prototype.pop.apply(arguments[0]);
    },
  };
})();

- Book Lists -