js怎么进行同步执行

JavaScript015

js怎么进行同步执行,第1张

**

* 解决异步加载问题

* */

function promise1(fun){

        this.fun1=function(){}

        this.fun2=function(){}

        try{

            fun(this.sol)

        }catch(err){

           

        }   

}

promise1.prototype={

fun1:function(){},

        fun2:function(){},

    sol:function(res){

        setTimeout(function(){

            promise1.prototype.fun1(res)

            promise1.prototype.fun2(res)

        },0)

    },

    then:function(fun1){

        promise1.prototype.fun1=fun1

        return this

    },

    err:function(fun2){

        promise1.prototype.fun2=fun2

    }

}

/**

*方法使用:方法1比方法2先执行

**/

new promise1(function(door){

functionA(door)//方法1

}).then(function(){

functionB()        //方法2

})

    functionA : fucntion(){

door

加载css. js 也一样.

<script>

doucment.write("<link rel='stylesheet' href='/fore/nec/css/base.css'")

</script>

你说的将存在文件中的数据加载到页面中,也不是多大的问题.关键在于你要加载的文件是存储在客户端还是在服务端

动态加载和静态加载指的是什么时候加载 ,动态加载是运行时加载(CommonJS),静态加载是编译时加载(ES6)。当然es6也提供的动态加载,即import() 。

同步加载还是异步加载指的是加载的方式。 静态加载中都是同步加载的。动态加载中CommonJS的require是同步的。而es6import()是异步的。