后盾人:JS课程第八章(函数)

函数基础

let hd = function() {}  //匿名函数没有变量提升
function hd() {}  //实名函数会有变量提升

 (function(){})()  //立即执行函数

//回调函数(回头调用的函数),在方法中调用的函数

函数中形参设置默认参数: function log(a = 1){console.log(a)}  //log()  a=1 //  log(3)  a=3

递归实现倒三角

 function star(sum) {
   return sum?document.write("*".repeat(sum) + "<br>")||star(--sum):""
 }
 star(10)

this状态

如果是普通函数this指向window

如果是箭头函数this指向上层this

this的构造原理

apply call 

同:call和apply为立即执行

异:call和apply 的区别传递参数时候,call用“,”逗号隔开;apply使用数组存放

function User(name) {
   this.name = name;
 }
let bd = {url: 'baidu.com'}
User.call(bd, "李四")
console.log(bd);//{url: 'baidu.com',name: '李四'}

bind  为不立即执行。需要再后面添加()括号

    生成一个新的函数

    适用于不需要立即执行的方法入 setinterval()

原文地址:https://www.cnblogs.com/jidanbufan/p/15152776.html