当前位置:网站首页>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>
边栏推荐
- Dongyuhui, New Oriental and Phoenix Satellite TV
- ProCAST有限元铸造工艺模拟软件
- Training notice | special training notice on epidemic prevention and security prevention for overseas Chinese funded enterprises, institutions and personnel in 2022
- Adding a new user in MySQL 5.7
- mysql-. SQL file phishing Online
- 买股票在中金证券经理的开户二维码上开户安全吗?求大神赐教
- Which programming language will attract excellent talents?
- Unity screenshot function
- Timestamp and date conversion "suggested collection"
- Day32 JS note event (Part 1) September 27, 2021
猜你喜欢

太阳能无线LED显示屏的特点

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

day34 js笔记 正则表达式 2021.09.29

Docker modifies the user name and password of MySQL

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

day37 js笔记 运动函数 2021.10.11

Jetpack Compose Desktop 桌面版本的打包和发布应用

String & heap & method area

js中的数组方法 2021.09.18
随机推荐
Graduated
Apache2 configuration denies access to the directory, but can access the settings of the files inside
JS foundation 3
Excel import / export convenience tool class
How to distinguish and define DQL, DML, DDL and DCL in SQL
合约量化交易系统开发 | 合约量化APP开发(现成案例)
Download and install mysql5.7 for windows 10
李宏毅《机器学习》丨7. Conclusion(总结)
Packaging and publishing application of jetpack compose desktop version
Gee: mcd64a1 based globfire daily fire data set
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
recent developments
毕业了
FTP protocol for Wireshark packet capture analysis
Basic 02: variable, remember the mobile number of the object
This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错
Pre parsing, recursive functions and events in day25 JS 2021.09.16
Day36 JS notes ecma6 syntax 2021.10.09
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
Day32 JS note event (Part 1) September 27, 2021