当前位置:网站首页>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 .
边栏推荐
- ClickPaaS低代码平台
- 企业级:Spire.Office for .NET:Platinum|7.7.x
- C # use awaiter
- UI automation test farewell to manual download of browser driver
- [untitled]
- What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
- Containerization Foundation
- Clickpaas low code platform
- JWT vulnerability recurrence
- Three level linkage demo of uniapp uview u-picker components
猜你喜欢
行为感知系统
Timing manager based on C #
阿里云ECS使用cloudfs4oss挂载OSS
Online text line fixed length fill tool
官宣!第三届云原生编程挑战赛正式启动!
Uni app change the default component style
如何实现实时音视频聊天功能
Why can't all browsers on my computer open web pages
Use of vscode software
Three level linkage demo of uniapp uview u-picker components
随机推荐
特殊版:SpreadJS v15.1 VS SpreadJS v15.0
About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
Online sql to excel (xls/xlsx) tool
[wp][introduction] brush weak type questions
C # use awaiter
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
Mixed compilation of C and CC
Use Firefox browser to quickly pick up Web image materials
“金九银十”是找工作的最佳时期吗?那倒未必
10种寻址方式之间的区别
Timing manager based on C #
NEW:Devart dotConnect ADO. NET
JWT vulnerability recurrence
WGS84 coordinate system, web Mercator, gcj02 coordinate system, bd09 coordinate system - brief introduction to common coordinate systems
This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
[charging station]_ Secular wisdom_ Philosophical wisdom _
【刷题】BFS题目精选
行为感知系统
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
长度为n的入栈顺序的可能出栈顺序