Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
cshuig
javascript_study
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
javascript_study
/
1.2_函数重载_reload.html
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
52 lines (45 loc) · 1.27 KB
master
Breadcrumbs
javascript_study
/
1.2_函数重载_reload.html
Copy path
Top
File metadata and controls
Code
Blame
52 lines (45 loc) · 1.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html PULBIC "-//W3C//DTD HTML 4.01/EN"
"http/www.w3.org/TR/html4/strict.dtd"
>
<
html
xmlns
="
http://www.w3.org/1999/xhmtl
"
lang
="
en
"
>
<
head
>
<
meta
http
=
equiv
="Content-Type" content="text/html; charset=utr-8"
/>
<
titl
>
1.2_函数的重载
</
title
>
<
meta
name
="
author
"
content
="
cshuig
"
/>
<
script
type
="
text/javascript
"
>
/*function sum(num1,num2){
return num1+num2;
}
function sum(num1){
return num1+100;
}*/
/*函数就是一个对象(特殊的对象)以上定义的两个函数实际的形式如下:*/
var
sum
=
function
(
num1
,
num2
)
{
return
num1
+
num2
;
}
var
sum
=
function
(
num1
)
{
return
num1
+
100
;
}
alert
(
sum
(
10
,
20
)
)
;
alert
(
sum
(
10
)
)
/*
以上写法,会导致第一个sum失效,原因是sum从第一块空间移到第二块空间,第一块空间变成垃圾空间
特别指出:函数的参数和调用没有关系,如果函数只有一个参数,但是却传入了两个参数,仅仅只会匹 配一个
所以在js中:函数不存在重载*/
/*函数有如下一种定义方式:
前面几个都是参数,最后一个参数是 函数体(要执行的代码),这些参数必须是字符串
下面函数的实际形式为:
function fn(num1,num2){
alert(num1+num2);
}
或者
var fn = function(num1,num2){
alert(num1+num2);
}
*/
var
fn
=
new
Function
(
"num1"
,
"num2"
,
"alert('fun:' + (num1+num2))"
)
;
fn
(
10
,
20
)
;
</
script
>
</
head
>
<
body
>
</
body
>
</
html
>
You can’t perform that action at this time.