0
点赞
收藏
分享

微信扫一扫

【js_02】函数和window对象

千行 2022-02-27 阅读 87

Preface:Wecome back again. Family

 


目录:

            一.函数

                1.自定义函数

                2.函数类型

                3.完成计算机功能

           二.window对象

                1.window对象

                1.window对象常用函数

                2.内置函数

本堂课新单词:

                       1. history 历史记录

                       2. screen 屏幕

                       3. location 准确位置

                       4. setTimeout 设置定时器

                       5. setInterval 设置循环定时器

                       6. clearTimeout 清除定时器

                       7. clearInterval 清除循环定时器

一.函数:

js 中的函数就相当于 java 中的方法

    java 中:
         public String fa(){
         }

        js中:
         fa() 调用方法

1.自定义函数解析图:

 

2.函数类型解析图:

3.函数使用计算机

 

//1.普通函数

         function fa(a){
             console.log("hello");
             if(a){
                 return "yes"
             }
             return false
         }

// 2.匿名函数

 (function(){
                 // 匿名函数和调用的方式
             })();

// 调用函数 console.log(fa(1,2,3,4,5,6))

// 3. 高阶函数   可以将函数作为参数 

 function fb(a,b){
                 return a(b)
             } 
             fb(fa,"1");

// 4.箭头函数 (普通函数的简写)

   var fb=()=>{
            // 是一个函数
            document.write("调用了")
        }

二.window对象

1.window 对象是整个 js 中最大的对象

 

2.window对象常用函数

// history 历史记录

    function f1(){
        // 百度
        location.href="https://www.baidu.com"
    }

// window.xx()

// window 默认可以不写

//setTimeout 定时器

//setInterval 循环定时器

//clearInterval 清除定时器

// 箭头函数 设置循环定时器

// 内置对象:

 

console.log(Math.max(1,2,3,4,5,6,7)) //最大值

console.log(Math.min(1,2,3,4,5,6,7)) //最小值

console.log(Math.ceil(1.99)) //向上取整

console.log(Math.floor(1.99)) //向下取整

console.log(Math.round(1.33)) //四舍五入

// 随机出来的一定是小数 [0,1) //包括0 不包括1

// 1~10

console.log(Math.floor(Math.rondom()*10)+1)

 

                                                  Thank you for your watch~

举报

相关推荐

0 条评论