当前位置:网站首页>JS foundation 10
JS foundation 10
2022-06-28 11:43:00 【Programmer community】
Function addition
- Self calling function
(function(){
console.log(' Self calling function ');
// The result is from calling the function
})()
effect : Form an independent scope space , Variables defined in space are private , It won't pollute the outside
2.arguments All argument sets , It's a pseudo array
There's a length Property determines the number of arguments
function fun(){
console.log(arguments);
// result Arguments [10, callee: ƒ, Symbol(Symbol.iterator): ƒ]
}
fun(10)
- this keyword
var obj={
fu: function(){
console.log(this);
// The object points to obj
}
}
obj.fu() divEle=document.querySelector('div') divEle.οnclick=function(){
console.log(this);
// The event object points to the event object
}
function fun(){
console.log(this);
// The global definition function points to window
}
fun() (function(){
console.log(this);
// The self calling function points to window
})() setTimeout(function(){
console.log(this);
},0)
// The timer function points to window
- change this Point to
- function .call( Point to a new object )
- function .call( Point to a new object , Parameters 1, Parameters 2)
- function .apply( Point to a new object )
- function .apply( Point to a new object ,[ Parameters 1, Parameters 2])
- var New functions = function .bind( Point to a new object ) New functions ( Parameters )
<script> var obj={
name:' Xiao Ming '
}
var obj2={
name:' floret '
}
var obj3={
name:' Xiaohua '
}
function test(a,b){
console.log(this);
console.log(a);
console.log(b);
}
test(1,2) //window 1 2 test.call(obj,1,2) //{
name: ' Xiao Ming '} 1 2 test.apply(obj2,[1,2]) //{
name: ' floret '} 1 2 var test2=test.bind(obj3) test2(1,2) //{
name: ' Xiaohua '} 1 2
</script>
- Arrow function
Definition : The short form of a function
<script> function fun(){
}
// It can't be abbreviated const fun=function(){
}; // It can be abbreviated const obj={
fun:function(){
}
// It can be abbreviated
}
</script>
Abbreviated form of arrow function
<script> divEle=document.querySelector('div') divEle.οnclick=function(e){
console.log(' Test abbreviation ');
}
// Parentheses can be abbreviated when there is only one parameter divEle.οnclick=e=>{
console.log(' Test abbreviation ');
}
// Only one line of code can abbreviate curly braces , Automatic addition return return
divEle.οnclick=e=>console.log(' Test abbreviation ')
</script>
- Deconstruct assignment
notes :object use {},array use []
let obj={
name:'jack',
age:18,
sex:' male '
}
let{
name,age}=obj let obj1={
arr:[1,2]}
let [a,b]=obj1.arr
application :
<script>
// Exchange two numbers
let a=10,
b=20;
[a,b]=[b,a]
console.log('a='+a+'b='+b);
// result a=20b=10 // Functions generally return only one value , Multiple values can be returned by deconstruction method function fun(){
return [1,2,3]
}
var [a,b,c]=fun()
console.log(a b c);
// result 1,2,3 // When passing parameters, deconstruction can be used to pass in... Out of order function person({
name,age}){
console.log(' I am a '+name+' Age '+age);
// As a result, I was jack Age 19
}
person({
age:19,name:'jack'}) // Deconstruction assignment can quickly take out the values in the array var arry=[10,20,30] var {
0:first,
2:last
}=arry
console.log(first);
// result 10
</script>
Expand operator …
<script>
// Expand array
let arry=[1,2,3]
console.log(...arry);
// result 1 2 3
// Expand the array and splice
let arr=[1,2,3]
let arr2=[...arr,4]
console.log(arr2);
//[1,2,3,4] // Expand the object and splice let obj={
name:'jack',
age:19
}
let obj1={
...obj,
sex:' male '
}
console.log(obj1);
// result {
name:'jack',age:19,sex:' male '}
</script>
边栏推荐
- Machine learning project captcha based on verification code recognition_ Trainer operation practice
- Day32 JS note event (Part 1) September 27, 2021
- MySQL cannot query the maximum value using the max function
- TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
- day31 js笔记 DOM下 2021.09.26
- [sciter]: use of sciter FS module scanning file API and its details
- 分析list中有无重复数据且重复了几次
- Create ECS using API shortcut
- Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
- Recommended practice sharing of Zhilian recruitment based on Nebula graph
猜你喜欢

人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors

QML控件类型:TabBar

Cannot redeclare block range variables
This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错

Docker modifies the user name and password of MySQL

Unity screenshot function

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

携手Cigent:群联为SSD主控固件引入高级网络安全防护特性

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
随机推荐
Unity屏幕截图功能
Industry analysis - quick intercom, building intercom
MySql5.7添加新用户
Graduation season, some suggestions for you who are new to the society
关于Pytorch中双向LSTM的输出表示问题
时间戳和date转换「建议收藏」
功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?
使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
Pre parsing, recursive functions and events in day25 JS 2021.09.16
Solutions to connection failures and errors when accessing mysql8 using the SSM project
soapui的菜鸟教程
day30 js笔记 BOM和DOM 2021.09.24
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
Create ECS using API shortcut
Contract quantitative trading system development | contract quantitative app development (ready-made cases)
Day30 JS notes BOM and DOM 2021.09.24
NFT卡牌链游系统开发dapp搭建技术详情
How to distinguish and define DQL, DML, DDL and DCL in SQL
recent developments
面试步骤的面试技巧