一个简单的堆栈,逻辑很清晰

简介: function Stack(type) { function QueueConst() {} QueueConst.execute_ing=[], QueueConst.
  function Stack(type) {
        function QueueConst() {}
        QueueConst.execute_ing=[],
        QueueConst.execute_no=[],
        QueueConst.state=1,
        QueueConst.type = type?type:false
        QueueConst.prototype.stop=function () {//暂停
        QueueConst.state=2
    }
        QueueConst.prototype.reset=function () { //恢复
        QueueConst.state=3
        QueueConst.prototype.execute();
    }
        QueueConst.prototype.execute=function () { //执行队列
        if(QueueConst.state==2) return;
        var currentItem = null
        if(QueueConst.execute_ing.length>0){
            currentItem = QueueConst.execute_ing.shift()
            if(QueueConst.type){
                currentItem(QueueConst.prototype.reset)
                QueueConst.prototype.stop()
            }else {
                currentItem()
                QueueConst.prototype.execute()
            }
            //执行当前
        }else {
            if(QueueConst.execute_no.length<1) {//完成队列里面的任务;
                QueueConst.state = 1
                return
            };
            QueueConst.execute_ing = QueueConst.execute_no.reverse()
            QueueConst.execute_no=[]
            QueueConst.prototype.execute()
        }
    }
        QueueConst.prototype.add=function (item) {//添加任务
        QueueConst.execute_no.push(item)
        if(QueueConst.state==1) QueueConst.state=3
        QueueConst.prototype.execute();
        }
        return new QueueConst()
}
    var que = Stack(true);
    que.add(function (next) {
        var index = 1;
        var loop = setInterval(function () {
            console.log(index++)
        },1000)
        setTimeout(function () {
            next();console.log('one')
            clearInterval(loop)
        },5000)
    })
    que.add(function (next) {
        var index = 1;
        var loop = setInterval(function () {
            console.log(index++)
        },1000)
        setTimeout(function () {
            next();console.log('two')
            clearInterval(loop)
        },3000)
    })
    que.add(function (next) {
        var index = 1;
        var loop = setInterval(function () {
            console.log(index++)
        },1000)
        setTimeout(function () {
            next();console.log('three')
            clearInterval(loop)
        },3000)
    })

  

http://www.cnblogs.com/jiebba/p/6575214.html 

http://www.cnblogs.com/jiebba    我的博客,来看吧!

如果有错误,请留言修改下 哦!

相关文章
|
7天前
|
人工智能 自然语言处理 文字识别
阿里云百炼Qwen3.7-Max简介:能力、优势、支持订阅计划参考
Qwen3.7-Max是阿里云百炼面向智能体时代推出的新一代旗舰模型,对标GPT-5.5、Claude Opus 4.7等闭源旗舰。该模型支持百万级token上下文窗口,具备顶级推理能力、多模态搜索与视觉理解增强、流式输出低延迟响应等核心优势,覆盖编程、办公、长周期自主执行等复杂场景。同时支持OpenAI接口兼容,便于系统快速迁移。用户可通过Token Plan团队或节省计划等订阅方式灵活调用,适合企业级高要求场景使用。
3479 15
阿里云百炼Qwen3.7-Max简介:能力、优势、支持订阅计划参考
|
15天前
|
人工智能 开发工具 iOS开发
Claude Code 新手完全上手指南:安装、国产模型配置与常用命令全解
Claude Code 是一款运行在终端环境中的 AI 编程助手,能够直接在命令行中完成代码生成、项目分析、文件修改、命令执行、Git 管理等开发全流程工作。它最大的特点是**任务驱动、终端原生、轻量高效、多模型兼容**,无需图形界面、不依赖 IDE 插件,能够深度融入开发者日常工作流。
3563 12
|
9天前
|
人工智能 自然语言处理 供应链
|
18天前
|
Shell API 开发工具
Claude Code 快速上手指南(新手友好版)
AI编程工具卷疯啦!Claude Code凭借任务驱动+终端原生的特性,成了开发者的效率搭子。本文从安装、登录、切换国产模型到常用命令,手把手带新手快速上手,全程避坑,30分钟独立用起来。
3683 25
|
11天前
|
人工智能 Linux BI
国内用 Claude Code 终于不用翻墙了:一行命令搞定,自动接 DeepSeek
JeecgBoot AI专题研究 一键脚本:Claude Code + JeecgBoot Skills + DeepSeek 全平台接入 一行命令装好 Claude Code + JeecgBoot Skills + DeepSeek 接入,无需翻墙使用 Claude Code,支持 Wind
2919 7
国内用 Claude Code 终于不用翻墙了:一行命令搞定,自动接 DeepSeek
|
9天前
|
人工智能 自然语言处理 安全
Claude Code 全攻略:命令大全+三种模式+记忆体系+实战工作流完整手册
Claude Code 是当前最流行的终端级 AI 编程助手,能够直接在命令行中完成代码生成、项目理解、文件修改、命令执行、错误修复等全流程开发工作。它不依赖图形界面、不占用额外资源,却能深度理解项目结构,自动生成规范代码,大幅提升研发效率。
1420 3
|
1月前
|
人工智能 JSON 供应链
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
LucianaiB分享零成本畅用JVS Claw教程(学生认证享7个月使用权),并开源GeoMind项目——将JVS改造为科研与产业地理情报可视化AI助手,支持飞书文档解析、地理编码与腾讯地图可视化,助力产业关系图谱构建。
23621 15
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
|
16天前
|
存储 Linux iOS开发
【2026最新】MarkText中文版Markdown编辑器使用图解(附安装包)
MarkText是一款免费开源、跨平台的Markdown编辑器,主打所见即所得实时预览,支持Windows/macOS/Linux。内置数学公式、流程图、代码高亮、多主题及PDF/HTML导出,是Typora的轻量免费替代首选。(239字)