当前位置:网站首页>Study notes 7
Study notes 7
2022-07-05 04:05:00 【The Journey of a Legendary Landscape Painting】
About js Some of our studies , I also touched a little before , But I don't understand it very well, and I haven't used it much recently , Recently, I watched the video shared by my sister , I learned something new , Simply take notes .
About variables
JavaScript Variables in usually pass var Keyword to declare :
var name="jun";
var age="19";
var name="jun",age="19";
Besides ,JavaScript Different data types can be stored in the same variable :
var school = “jxnu”;
school = 123;
in addition ,JavaScript You can use it directly without declaring variables , for example :
var text1="i am a student";
text2=text1+"from china";
javascript When encountering undeclared variables , It will automatically create a global variable , For good usage , Variables should be declared .
in addition , Variable declarations should follow the following rules ,
The first letter of the variable can be upper and lower case English letters , Underline or dollars “$” Symbol
The remaining letters can be underlined , Case letters , Any number or dollar "$" Symbol
The name of a variable cannot be a reserved word or keyword .
Here are some illegal The variable name of :
var 1abc; // The beginning of the number
var hdj“ksjh; // Single quotation marks
var false; //false Is the key word
Function objects and function expressions
Function declaration :function The name of the function ( Parameters : Optional ){ The body of the function }
Function expression :function The name of the function ( Optional )( Parameters : Optional ){ The body of the function }
function foo(){} // Statement , Because it's part of the program
var bar = function foo(){}; // expression , Because it's part of an assignment expression
new function bar(){}; // expression , Because it is new expression
(function(){
function bar(){} // Statement , Because it's part of the function body
})();
If function foo(){} As part of an assignment expression , So it's a function expression
If function foo(){} Contained in a function , Or at the top of the program , So it's a function declaration .
If function foo(){} As part of an assignment expression , So it's a function expression
If function foo(){} Contained in a function , Or at the top of the program , So it's a function declaration .
alert(fn());
function fn() {
return 'Hello world!';
}
Name functions and expressions
Mention named function expressions , It has to have a name , The previous example var bar = function foo(){}; Is a valid named function expression , But one thing to remember : This name is only valid in the newly defined function scope .
var f = function foo(){
return typeof foo; // function --->foo Is valid in internal scope
};
// foo Used externally is invisible
typeof foo; // "undefined"
f(); // "function"
call(),apply() Method
JavaScript Pass through call perhaps apply To call a method instead of another object , Change the object context of a function from the initial context to thisObj New object specified .
Simply put, change the context of function execution , This is the most basic usage . The basic difference between the two methods is that the parameters are different .
call(obj,arg1,arg2,arg3); call The first parameter is passed to the object , It can be null. Parameters are passed values separated by commas , Parameters can be of any type .
apply(obj,[arg1,arg2,arg3]); apply The first parameter is passed to the object , Parameters can be arrays or arguments object .
for example :
function sum(num1, num2){
return num1 + num2;
}
function callSum1(num1, num2){
return sum.apply(this, arguments); // Pass in arguments object
}
function callSum2(num1, num2){
return sum.apply(this, [num1, num2]); // Pass in array
}
alert(callSum1(10,10)); //20
alert(callSum2(10,10)); //20
In addition, this week about js And while,if sentence ,arguement Detailed explanation , Basic types , Reference type . and break and continue sentence , I did some related questions .
边栏推荐
- Containerd series - detailed explanation of plugins
- Get to know MySQL connection query for the first time
- Rust区块琏开发——签名加密与私钥公钥
- Online text line fixed length fill tool
- 灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
- Alibaba cloud ECS uses cloudfs4oss to mount OSS
- How does the applet solve the rendering layer network layer error?
- 在线SQL转Excel(xls/xlsx)工具
- Interview byte, pass the exam and directly work on three sides. As a result, I found an architect to hang me?
- [understand series after reading] 6000 words teach you to realize interface automation from 0 to 1
猜你喜欢
北京程序员的真实一天!!!!!
MindFusion.Virtual Keyboard for WPF
一文带你了解BI的前世今身与企业数字化转型的关系
【看完就懂系列】一文6000字教你从0到1实现接口自动化
Redis source code analysis: redis cluster
陇原战“疫“2021网络安全大赛 Web EasyJaba
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
A real day for Beijing programmers!!!!!
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
Rust区块琏开发——签名加密与私钥公钥
随机推荐
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
Special Edition: spreadjs v15.1 vs spreadjs v15.0
Analysis of dagger2 principle
Longyuan war "epidemic" 2021 network security competition web easyjaba
provide/inject
laravel8 导出Excle文件
kubernetes集群之调度系统
The new project Galaxy token just announced by coinlist is gal
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
Laravel8 export excel file
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 2)
About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
Alibaba cloud ECS uses cloudfs4oss to mount OSS
基于TCP的移动端IM即时通讯开发仍然需要心跳保活
C # use awaiter
What is test development? Why do so many companies hire test developers now?
Redis source code analysis: redis cluster
PlasticSCM 企业版Crack
[charging station]_ Secular wisdom_ Philosophical wisdom _
如何实现实时音视频聊天功能