beautify 1st part of the tutorial

This commit is contained in:
Ilya Kantor 2015-03-10 12:36:58 +03:00
parent e3dd2cedc0
commit 6444024a9d
327 changed files with 2358 additions and 1986 deletions

View file

@ -5,7 +5,7 @@
Например, они могут вернуть один и тот же объект `obj`, определённый снаружи:
```js
//+ run
//+ run no-beautify
var obj = {};
function A() { return obj; }

View file

@ -5,6 +5,7 @@
Возможны ли такие функции `A` и `B` в примере ниже, что соответствующие объекты `a,b` равны (см. код ниже)?
```js
//+ no-beautify
function A() { ... }
function B() { ... }

View file

@ -5,7 +5,7 @@
function Calculator() {
this.read = function() {
this.a = +prompt('a?', 0);
this.a = +prompt('a?', 0);
this.b = +prompt('b?', 0);
};

View file

@ -20,7 +20,7 @@ function Calculator() {
op = split[1],
b = +split[2]
if(!methods[op] || isNaN(a) || isNaN(b)) {
if (!methods[op] || isNaN(a) || isNaN(b)) {
return NaN;
}
@ -45,7 +45,7 @@ calc.addMethod("**", function(a, b) {
});
var result = calc.calculate("2 ** 3");
alert(result); // 8
alert( result ); // 8
```
<ul>

View file

@ -13,7 +13,7 @@
```js
var calc = new Calculator;
alert(calc.calculate("3 + 7")); // 10
alert( calc.calculate("3 + 7") ); // 10
```
</li>
@ -23,12 +23,18 @@ alert(calc.calculate("3 + 7")); // 10
```js
var powerCalc = new Calculator;
powerCalc.addMethod("*", function(a, b) { return a * b; });
powerCalc.addMethod("/", function(a, b) { return a / b; });
powerCalc.addMethod("**", function(a, b) { return Math.pow(a, b); });
powerCalc.addMethod("*", function(a, b) {
return a * b;
});
powerCalc.addMethod("/", function(a, b) {
return a / b;
});
powerCalc.addMethod("**", function(a, b) {
return Math.pow(a, b);
});
var result = powerCalc.calculate("2 ** 3");
alert(result); // 8
alert( result ); // 8
```
</li>

View file

@ -13,7 +13,7 @@
```js
function Animal(name) {
this.name = name;
this.canWalk = true;
this.canWalk = true;
}
*!*
@ -52,7 +52,7 @@ function Animal(name) {
// в this пишем свойства, методы
this.name = name;
this.canWalk = true;
this.canWalk = true;
*!*
// return this
@ -75,7 +75,7 @@ function Animal(name) {
Например, возврат объекта:
```js
//+ run
//+ run no-beautify
function BigAnimal() {
this.name = "Мышь";
@ -97,7 +97,7 @@ function BigAnimal() {
return "Годзилла"; // <-- возвратим примитив
}
alert( new BigAnimal().name ); // Мышь, получили this (а Годзилла пропал)
alert( new BigAnimal().name ); // Мышь, получили this (а Годзилла пропал)
```
Эта особенность работы `new` прописана в стандарте, но используется она весьма редко.
@ -126,9 +126,9 @@ var animal = new BigAnimal();
//+ run
function User(name) {
this.name = name;
this.sayHi = function() {
alert("Моё имя: " + this.name);
alert( "Моё имя: " + this.name );
};
}
@ -156,15 +156,15 @@ function User(firstName, lastName) {
*!*
// вспомогательная переменная
var phrase = "Привет";
// вспомогательная вложенная функция
function getFullName() {
return firstName + " " + lastName;
}
function getFullName() {
return firstName + " " + lastName;
}
*/!*
this.sayHi = function() {
alert(phrase + ", " + getFullName()); // использование
alert( phrase + ", " + getFullName() ); // использование
};
}