-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutMutability.js
More file actions
68 lines (53 loc) · 2.03 KB
/
Copy pathAboutMutability.js
File metadata and controls
68 lines (53 loc) · 2.03 KB
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("Alan");
});
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("Alan");
});
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('John Smith');
aPerson.getFullName = function() {
return this.lastname + ", " + this.firstname;
};
expect(aPerson.getFullName()).toBe('John Smith');
});
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 ('Smith, John');
aPerson.firstname = "Penny";
aPerson.lastname = "Andrews";
aPerson.fullName = "Penny Andrews";
expect(aPerson.getFirstName()).toBe('John');
expect(aPerson.getLastName()).toBe('Smith');
expect(aPerson.getFullName()).toBe('John Smith');
aPerson.getFullName = function() {
return aPerson.lastname + ", " + aPerson.firstname;
};
expect(aPerson.getFullName()).toBe('Andrews, Penny');
});
});