1 | // var HomeMessage = function (name, success, error) { |
||
2 | // this.name = name; |
||
3 | // this.success = success; |
||
4 | // this.error = error; |
||
5 | // |
||
6 | // this.create = function (data) { |
||
7 | // restSubmit(this.name, 'GET', data, this.success, this.error); |
||
8 | // } |
||
9 | // |
||
10 | // }; |
||
11 | |||
12 | |||
13 | var Message = function (selector) { |
||
14 | this.selector = selector; |
||
15 | |||
16 | |||
17 | this.add = function (message) { |
||
18 | console.log(message); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
19 | var classname = null; |
||
20 | |||
21 | if (typeof classname !== 'string') { |
||
22 | classname = 'home-messages'; |
||
23 | } |
||
24 | handle = document.getElementsByClassName(classname) |
||
0 ignored issues
–
show
|
|||
25 | if (handle) |
||
26 | |||
27 | var node = document.createElement("LI"); // Create a <li> node |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
28 | var textnode = document.createTextNode(message); // Create a text node |
||
29 | node.appendChild(textnode); |
||
0 ignored issues
–
show
|
|||
30 | document.getElementsByClassName(classname)[0].appendChild(node); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | |||
35 | function AddMessage(text, classname) { |
||
36 | var message = new Message(classname); |
||
37 | message.add(text); |
||
38 | } |
||
39 |