Javascript本身是不支持多线程的,直到在网上看到这样一篇文章, javascript中用command模式模拟多线程中 ,觉得非常好,用command模式,巧妙的模拟了多线程.虽是模拟,但很实用.对于javascript不熟的人,可能很难去理解,因此添加了注释,重新发布出来。希望能给需要的人一点帮助。
<html>
在Javascript中用command模式模拟多线程,包含注释    
<head>
在Javascript中用command模式模拟多线程,包含注释        
<title>用command模式模拟多线程</title>
在Javascript中用command模式模拟多线程,包含注释    
</head>
在Javascript中用command模式模拟多线程,包含注释    
<body>
在Javascript中用command模式模拟多线程,包含注释    
<script language="JavaScript" type="text/javascript">
在Javascript中用command模式模拟多线程,包含注释    
<!--
在Javascript中用command模式模拟多线程,包含注释     
//objectName.prototype:返回Array对象类型原型的引用
在Javascript中用command模式模拟多线程,包含注释
     //命令出队列,返回第一个元素
在Javascript中用command模式模拟多线程,包含注释
     if (Array.prototype.shift==null)
在Javascript中用command模式模拟多线程,包含注释     Array.prototype.shift 
= function ()
>


上面值得说明的是几个对象:
一,CommandList为一个ArrayList对象,可以通过ArrayList.shift()取出第一个元素,可通过ArrayList.push()将元素放进去.其ArrayList中保存的对象为Command.
二,Command对象为一个函数如下,可以直接执行.
  function (){simThread(resultTemp,n);}其中n是可以传递的变量
三,command.constructor即FunctionConstructor
    function Function()
      {
          [native code]
       }

相关文章:

  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-10-05
猜你喜欢
  • 2022-03-08
  • 2021-11-20
  • 2022-12-23
  • 2021-05-21
  • 2021-06-02
  • 2021-05-20
  • 2021-08-01
相关资源
相似解决方案