前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >前端预编译流程

前端预编译流程

作者头像
爱学习的前端歌谣
发布2023-11-06 15:17:02
2070
发布2023-11-06 15:17:02
举报
文章被收录于专栏:前端小歌谣

前言

我是歌谣 最好的种树是十年前 其次是现在 今天继续给大家带来的是预编译基础的讲解

环境配置

代码语言:javascript
复制
npm init -y
yarn add vite -D

修改page.json配置端口

代码语言:javascript
复制
{
  "name": "demo1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "vite --port 3002"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "vite": "^4.4.9"
  }
}

案例1

代码语言:javascript
复制
var a=1
b=1
console.log(window.a)
window={
    a:1,
    b:2
}

运行结果

案例2

代码语言:javascript
复制
function test(){
    var a=b=1
}
test()
console.log(window.a)
console.log(window.b)

运行结果

案例3

代码语言:javascript
复制
function test(a){
    console.log(a)
    var a=1
    console.log(a)
    function a(){


    }
    console.log(a)
    var b=function(){}
    console.log(b)
    function d(){


    }
}
//AO
//AO={
//   a:undefined->2->function a(){}->1
//   b:undefined->function b(){}
//   d:function d(){}
//}
//
test(2)

运行结果

案例4

代码语言:javascript
复制
function test(a,b){
    console.log(a)
    c=0
    var c;
    a=5;
    b=6;
    console.log(b)
    function b(){}
    function d(){}
    console.log(b)
}
test(1)
// AO{
//    a:undefined-->a-->5
//    b:undefined-->function b(){}-->6
//    c:undefined-->0
//    d:function d(){}
//}

运行结果

案例5

代码语言:javascript
复制
var a=1;
function a(){
    console.log(2)
}
console.log(a)
// GO{
//  a:undefined-->function a(){}--->1
//
//}

运行结果

案例6

代码语言:javascript
复制
console.log(a,b)
function a(){}
var b=function(){}
// GO{
//  a:undefined---->function a(){}
//  b:a:undefined
//}

运行结果

案例7

代码语言:javascript
复制
function test(){
    var a=b=1;
    console.log(b)
}
test()
//GO={
//  b:1
//}
//AO{
//  a:undefined--->1
//}

运行结果

案例8

代码语言:javascript
复制
var b = 3
console.log(a)
function a(a) {
    console.log(a)
    var a = 2;
    console.log(a)
    function a() {
    }
    var b = 5;
    console.log(b)
}
a(1)


//AO{
//   a:undefined--->1---->function a()--->2
//   b:undefined--->5
//
//}
//GO{
//   b:undefined--->3
//   a:function a(){}
//}

运行结果

案例9

代码语言:javascript
复制
a=1
function test(){
    console.log(a)
    a=2
    console.log(a)
    var a=3
    console.log(a)
}
test()
var a;
//GO{
//  a:undefined--->1
// test:function test(){}
//}
//AO{
//  a:undefined--->2--->3
//
//}

运行结果

案例10

代码语言:javascript
复制
function test(){
    console.log(b)
    if(a){
        var b=2
    }
    c=3;
    console.log(c)
}
var a;
test()
a=1
console.log(a)
// AO{
//   
//    b:undefined-->2
//    
//}
//GO{
//   a:undefined-->1
//   test:function test(){}
//   c:3
//}

运行结果

案例11

代码语言:javascript
复制
function test(){
    return a;
    a=1;
    function a(){


    }
    var a=2
}
console.log(test())
// AO{
//    a:undefined---->function a(){}
//
//}
//

运行结果

案例12

代码语言:javascript
复制
console.log(test())
function test(){
    a=1
    function a(){


    }
    var a=2
    return a
}


//AO{
//  a:undefined--->function a(){}-->1--->2
//
//
//}
//

运行结果

案例13

代码语言:javascript
复制
a=1
function test(e){
    function e(){}
    arguments[0]=2
    console.log(e)
    if(a){
        var b=3
    }
    var c;
    a=4;
    var a;
    console.log(b)
    f=5
    console.log(c)
    console.log(a)
}
var a;
test(1)
console.log(a)
console.log(f)
//GO{
//  a:undefined-->1
//   test:function test(){}
//   f:5
//}
//AO{
//   e:undefined---->1---->function e(){}--->2
//   b:undefined
//   c:undefined
//   a:undefined---->4
//}

运行结果

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-11-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 前端小歌谣 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档