当前位置:网站首页>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 .
边栏推荐
- Longyuan war "epidemic" 2021 network security competition web easyjaba
- 陇原战“疫“2021网络安全大赛 Web EasyJaba
- ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
- PlasticSCM 企业版Crack
- A real day for Beijing programmers!!!!!
- WGS84 coordinate system, web Mercator, gcj02 coordinate system, bd09 coordinate system - brief introduction to common coordinate systems
- Pyqt pyside custom telescopic menu bar sharing (including tutorial)
- English essential vocabulary 3400
- Number of possible stack order types of stack order with length n
- [brush questions] BFS topic selection
猜你喜欢
Why can't all browsers on my computer open web pages
DMX parameter exploration of grandma2 onpc 3.1.2.5
Rust区块琏开发——签名加密与私钥公钥
How to realize real-time audio and video chat function
Redis之Jedis如何使用
Installation of postman and postman interceptor
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
laravel8 导出Excle文件
Wechat applet development process (with mind map)
Threejs implements labels and displays labels with custom styles
随机推荐
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 2)
我就一写代码的,王总整天和我谈格局...
C language course setting: cinema ticket selling management system
[wp]bmzclub writeup of several questions
About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
Thread Basics
Web components series (VII) -- life cycle of custom components
Number of possible stack order types of stack order with length n
mysql的七种join连接查询
Online text line fixed length fill tool
How does the applet solve the rendering layer network layer error?
Timing manager based on C #
[charging station]_ Secular wisdom_ Philosophical wisdom _
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
Phpmailer reported an error: SMTP error: failed to connect to server: (0)
[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1
Rust区块琏开发——签名加密与私钥公钥
Threejs rendering obj+mtl model source code, 3D factory model