当前位置:网站首页>5. Reference type and value type as function parameters?
5. Reference type and value type as function parameters?
2022-07-24 18:21:00 【yingxingyf】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value=" test " onclick ="testf()" />
</body>
</html>
<script type="text/javascript">
/*
function testf(){
var m = 20;
var n = 30;
var t = max(m,n);
console.log(t);
}
//1、 Value type as parameter of function : Value passed .
function max(x,y){
var m;
if(x>y){
m = x;
}else{
m = y;
}
return m;
}
*/
function testf(){
var ages = [28,10,19,25,21,38,8];
bubble(ages);
for(var i in ages){
document.write(ages[i]+",");
}
}
//2、 Reference types as arguments to functions , It's address delivery ( The address saved in the argument was passed to the formal parameter , That is, the arguments and formal parameters point to the same memory area )
// Bubble sort
// Parameters : Array ( A disorderly )
// Return value : Array ( In order )
function bubble(arr){
for(var i=0;i<arr.length-1;i++){
for(var j=0;j<arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] =temp;
}
}
}
return arr;
}
function bubble2(arr){
var arrnew = [];// A new address has been opened in the pile
for(var i=0;i<arr.length-1;i++){
for(var j=0;j<arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] =temp;
}
}
}
return arr;
}
</script>
1. Schematic diagram of value type as function parameter :
2. quote ( object ) Type as function parameter diagram :
边栏推荐
猜你喜欢
随机推荐
[opencv] - thresholding
可撤销并查集板子
Example of single table query in ORM student management system
About the writing method of interface 1 chain interpretation 2. Method execution (finally) must be executed
0611~ self study class
球面上绘制圆matlab仿真
Install jumpserver
模拟实现vector
0627~ holiday knowledge summary
Baidu touch.js
第五届数字中国建设峰会在福建福州开幕
Get the original data API on 1688app
A practical scheme of realizing 0.5px on mobile terminal
odoo中的bom理解
BOM understanding in odoo
线段树合并板子
Cookies and session "suggestions collection"
继承与派生
Simple test JS code
Problems needing attention in writing pages




![[OBS] dependency Library: x264 vs Build](/img/24/4caea5dc6ff092a3161f43b6026d25.png)




