Files
ClassContent/历届学生/陈一航/2020-04-01/index.html
2024-09-27 02:06:13 +08:00

78 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js 方法(函数)</title>
</head>
<body>
<script>
// js 方法(函数) 数据类型之一
// 作用:封装具有相同逻辑或者作用(功能)的代码
// 1定义function 函数名() {}
// 2调用
// 计算长方形面积
// 如果想拿到方法的返回值,使用 return 返回方法的最终计算结果给方法调用者
// 给钱的过程:向方法传递参数
// 不传参数的方法:无参函数(方法)
// 传参数的方法:有参函数(方法)
// arguments 可以将方法的参数全部获取到,不需要定义变量接受参数
function YourName () {
var result;
for(var i =0;i<arguments.length;i++) {
if ( !(i + 1 > 1) ) {
result = arguments[i] * arguments[i+1]
}
}
return result
}
console.log(result)
// var a = 100, b = 300;
// var mianji = YourName(a,b);
// console.log(mianji);
// var a = 1;
// // 方法内部会形成一个独立的作用域
// // 全局作用域
// // 局部作用域
// // 定义变量不加var会被js解析器进行变量提升
// function GolabVar () {
// }
// // 使用 prototype 原型向方法中追加 age变量
// prototype 在方法内里面使用
// 一般封装原生js插件的时候会用到或者模拟类的时候
// 在vue里面是用来注册全局方法的
// GolabVar.prototype.age = 18
// GolabVar.prototype.getName = function () {
// return "刘兵"
// }
// // 初始化方法让方法变为object
// var ddd = new GolabVar()
// console.log(ddd.age)
// console.log(ddd.getName())
// 第二种定义方法的方式
// var GetName = function () {
// }
// function GetName() {}
</script>
</body>
</html>