FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript/javascript-based/namespace/namespace.HTML at master · wchaowu/javascript · GitHub
wchaowu
/
javascript
Public
Notifications
You must be signed in to change notification settings
Fork
312
Star
682
Code
Issues
3
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript
/
javascript-based
/
namespace
/
namespace.HTML
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (49 loc) · 1.45 KB
Breadcrumbs
javascript
/
javascript-based
/
namespace
/
namespace.HTML
Copy path
File metadata and controls
63 lines (49 loc) · 1.45 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
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
title
>
命名空间的注入
</
title
>
<
meta
name
="
Generator
"
content
="
Vbooking System
"
>
<
meta
name
="
Author
"
content
="
cwwu
"
>
<
meta
name
="
Keywords
"
content
=""
>
<
meta
name
="
Description
"
content
=""
>
<
meta
http-equiv
="
Content-Type
"
content
="
text/html; charset=utf-8
"
/>
</
head
>
<
body
>
<
script
type
="
text/javascript
"
>
var
myApp
=
myApp
||
{
}
;
myApp
.
utils
=
{
}
;
(
function
(
)
{
var
val
=
5
;
this
.
getValue
=
function
(
)
{
return
val
;
}
;
this
.
setValue
=
function
(
newVal
)
{
val
=
newVal
;
}
// also introduce a new sub-namespace
this
.
tools
=
{
}
;
}
)
.
apply
(
myApp
.
utils
)
;
// inject new behaviour into the tools namespace
// which we defined via the utilities module
(
function
(
)
{
this
.
diagnose
=
function
(
)
{
return
"diagnosis"
;
}
}
)
.
apply
(
myApp
.
utils
.
tools
)
;
// note, this same approach to extension could be applied
// to a regular IIFE, by just passing in the context as
// an argument and modifying the context rather than just
// "this"
// Usage:
// Outputs our populated namespace
console
.
log
(
myApp
)
;
// Outputs: 5
console
.
log
(
myApp
.
utils
.
getValue
(
)
)
;
// Sets the value of `val` and returns it
myApp
.
utils
.
setValue
(
25
)
;
console
.
log
(
myApp
.
utils
.
getValue
(
)
)
;
// Testing another level down
console
.
log
(
myApp
.
utils
.
tools
.
diagnose
(
)
)
;
</
script
>
</
body
>
</
html
>
Back
|
FazBrowse Home
|
New Git URL