当前位置:网站首页>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 .
边栏推荐
- 10种寻址方式之间的区别
- Differences among 10 addressing modes
- [charging station]_ Secular wisdom_ Philosophical wisdom _
- provide/inject
- Rust blockchain development - signature encryption and private key public key
- 小程序中实现文章的关注功能
- BDF application - topology sequence
- Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
- It took two nights to get Wu Enda's machine learning course certificate from Stanford University
- Analysis of dagger2 principle
猜你喜欢
C语言课设:影院售票管理系统
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
MindFusion.Virtual Keyboard for WPF
IronXL for .NET 2022.6
Uni app common functions /api
线上故障突突突?如何紧急诊断、排查与恢复
This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
阿里云ECS使用cloudfs4oss挂载OSS
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
kubernetes集群之调度系统
随机推荐
provide/inject
Rome chain analysis
A應用喚醒B應該快速方法
Phpmailer reported an error: SMTP error: failed to connect to server: (0)
[wp][introduction] brush weak type questions
[brush questions] BFS topic selection
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
[punch in questions] integrated daily 5-question sharing (phase III)
Wechat applet development process (with mind map)
[数组]566. 重塑矩阵-简单
Differences among 10 addressing modes
Containerization Foundation
A real day for Beijing programmers!!!!!
JVM garbage collection
The development of mobile IM based on TCP still needs to keep the heartbeat alive
JWT vulnerability recurrence
ClickPaaS低代码平台
speed or tempo in classical music
反絮凝剂-氨碘肽滴眼液
NEW:Devart dotConnect ADO.NET