forked from mrdavidlaing/javascript-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAboutMutability.js
68 lines (53 loc) · 2 KB
/
AboutMutability.js
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
64
65
66
67
68
describe("About Mutability", function() {
it("should expect object properties to be public and mutable", function () {
var aPerson = {firstname: "John", lastname: "Smith" };
aPerson.firstname = "Alan";
expect(aPerson.firstname).toBe(FILL_ME_IN);
});
it("should understand that constructed properties are public and mutable", function () {
function Person(firstname, lastname)
{
this.firstname = firstname;
this.lastname = lastname;
}
var aPerson = new Person ("John", "Smith");
aPerson.firstname = "Alan";
expect(aPerson.firstname).toBe(FILL_ME_IN);
});
it("should expect prototype properties to be public and mutable", function () {
function Person(firstname, lastname)
{
this.firstname = firstname;
this.lastname = lastname;
}
Person.prototype.getFullName = function () {
return this.firstname + " " + this.lastname;
};
var aPerson = new Person ("John", "Smith");
expect(aPerson.getFullName()).toBe(FILL_ME_IN);
aPerson.getFullName = function () {
return this.lastname + ", " + this.firstname;
};
expect(aPerson.getFullName()).toBe(FILL_ME_IN);
});
it("should know that variables inside a constructor and constructor args are private", function () {
function Person(firstname, lastname)
{
var fullName = firstname + " " + lastname;
this.getFirstName = function () { return firstname; };
this.getLastName = function () { return lastname; };
this.getFullName = function () { return fullName; };
}
var aPerson = new Person ("John", "Smith");
aPerson.firstname = "Penny";
aPerson.lastname = "Andrews";
aPerson.fullName = "Penny Andrews";
expect(aPerson.getFirstName()).toBe(FILL_ME_IN);
expect(aPerson.getLastName()).toBe(FILL_ME_IN);
expect(aPerson.getFullName()).toBe(FILL_ME_IN);
aPerson.getFullName = function () {
return aPerson.lastname + ", " + aPerson.firstname;
};
expect(aPerson.getFullName()).toBe(FILL_ME_IN);
});
});