FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript_design_patterns/PrototypePattern.js at master · colbisaurusrex/javascript_design_patterns · GitHub
colbisaurusrex
javascript_design_patterns
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript_design_patterns
/
PrototypePattern.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (19 loc) · 487 Bytes
Breadcrumbs
javascript_design_patterns
/
PrototypePattern.js
Copy path
File metadata and controls
25 lines (19 loc) · 487 Bytes
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
/* Prototype Pattern */
// TLDR; pattern that creates objects based on a template of an existing object through cloning
var
vehicleProtoType
=
{
init
:
function
(
carModel
)
{
this
.
model
=
carModel
;
}
,
getModel
:
function
(
)
{
console
.
log
(
"The model of this vehicle is..."
+
this
.
model
)
;
}
}
;
function
vehicle
(
model
)
{
function
F
(
)
{
}
F
.
prototype
=
vehicleProtoType
;
var
f
=
new
F
(
)
;
f
.
init
(
model
)
;
return
f
;
}
var
car
=
vehicle
(
"Ford Escort"
)
;
car
.
getModel
(
)
;
Back
|
FazBrowse Home
|
New Git URL