-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheat-sheet.html
61 lines (60 loc) · 1.68 KB
/
cheat-sheet.html
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
<!doctype.html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CheatSheet</title>
<link rel="stylesheet" href="cheat-sheet.css" />
</head>
<body>
<header>
Javascript Objects
</header>
<div class="gridwrapper">
<div class="intro">
<p>
<h5>And Introduction to JS Objects</h5>
Javascript Object is a combination of a Ruby class and a Ruby Hash.
In keeping in line with object orientated principles, a JS object has properties and methods attached to it.
Javascript Objects can be created using literal and constructor notation. Properties are assigned using name value pairs similar to a Ruby hash.</p>
<!-- <code>Array.prototype.each = function (callback) {
for (var i = 0; i < this.length; i++)
callback(this[i]);
</code> -->
</div>
<div class="create">
<p>
<h5>Creating Objects</h5>
<code>var hat = { <br>
style: "baseball", <br>
color: "grey", <br>
brand: "Obey" <br>
}, <br>
</code></p>
</div>
<div class="add">
<p>
<h5>Adding Methods</h5>
<code>
hat.whatColor = function() { <br>
this.color <br>
}; <br>
console.log(hat.whatColor) <br>
</code></p>
</div>
<div class="proto">
<p>
<h5>Using Prototypes to create Objects:</h5>
<code>
function Hat(style, color, brand) { <br>
this.style = style; <br>
this.color = color; <br>
this.brand = brand; <br>
} <br>
var myHat = new Hat("fedora", "black", "Goorin Bros.");<br>
</code>
</p>
</div>
</div>
</div>
</body>