Skip to content

Commit e1a6af6

Browse files
committed
Started translation in Bulgarian
1 parent d6363c5 commit e1a6af6

File tree

7 files changed

+413
-1
lines changed

7 files changed

+413
-1
lines changed

doc/bg/index.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Градината на JavaScript",
3+
"langTitle": "Градината на JavaScript на български",
4+
"description": "Ръководство за особеностите и пропуските в JavaScript.",
5+
"sections": [
6+
{
7+
"title": "Увод",
8+
"dir": "intro",
9+
"articles": ["index"]
10+
},
11+
{
12+
"title": "Обекти",
13+
"dir": "object",
14+
"articles": [
15+
"general",
16+
"prototype",
17+
"hasownproperty",
18+
"forinloop"
19+
]
20+
}
21+
]
22+
}

doc/bg/intro/index.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Увод
2+
3+
**Градината на JavaScript** е нарастваш набор от документи, засягащ най-странните
4+
части на езика за програмиране ДжаваСкрипт (по-нататък JavaScript,
5+
бел. пр.). Наръчникът дава съвети за избягване на обичайни и трудно-откриваеми
6+
грешки, преодоляване на затруднения, свързани с производителността както и
7+
лоши практики, с които начинаещите програмисти на JavaScript могат да се
8+
сблъскат, опитвайки се да овладеят езика в дълбочина.
9+
10+
Градината на JavaScript **няма за цел** да ви научи да програмирате на JavaScript. За да можете да разберете засегнатите въпроси, познаването на езика до някаква степен е силно препоръчително. За да научите основните положения в езика, прочетете [ръководството][1] в Мрежата за Разработчици на Мозила (Mozilla Developer Network).
11+
12+
## Авторите
13+
14+
Това ръководство е резултат от работата на двама възхитителни потребители на
15+
[Stack Overflow][2] -- [Ivo Wetzel][3] (писане) и [Zhang Yi Jiang][4] (външен вид).
16+
17+
По време на превода се поддържа от [Tim Ruffles](http://truffles.me.uk).
18+
19+
## Участници
20+
21+
Твърде много са, за да бъдат изредени тук. [Вижте всички
22+
участници](https://github.com/BonsaiDen/JavaScript-Garden/graphs/contributors).
23+
24+
## Преводачи
25+
26+
Преводът на български бе започнат от [Красимир Беров](https://github.com/kberov).
27+
28+
29+
## Хостинг
30+
31+
"Градината на JavaScript" се намира на GitHub, но [Cramer Development][7] ни помага с огледално копие на [JavaScriptGarden.info][8].
32+
33+
## License
34+
35+
"Градината на JavaScript" е публикуван под [лиценза MIT][9] и се намира на
36+
[GitHub][10]. Ако намерите грешки, моля [пишете][11] или отстранете грешката
37+
и създайте заявка за добавяне (pull request) на промяната в нашето хранилище.
38+
Също така можете да ни намерите в стаята, посветена на [JavaScript][12] в чата
39+
на Stack Overflow.
40+
41+
[1]: https://developer.mozilla.org/en/JavaScript/Guide
42+
[2]: http://stackoverflow.com/
43+
[3]: http://stackoverflow.com/users/170224/ivo-wetzel
44+
[4]: http://stackoverflow.com/users/313758/yi-jiang
45+
[5]: https://github.com/caio
46+
[6]: https://github.com/blixt
47+
[7]: http://cramerdev.com/
48+
[8]: http://javascriptgarden.info/
49+
[9]: https://github.com/BonsaiDen/JavaScript-Garden/blob/next/LICENSE
50+
[10]: https://github.com/BonsaiDen/JavaScript-Garden
51+
[11]: https://github.com/BonsaiDen/JavaScript-Garden/issues
52+
[12]: http://chat.stackoverflow.com/rooms/17/javascript

doc/bg/object/forinloop.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## The `for in` Loop
2+
3+
Just like the `in` operator, the `for in` loop traverses the prototype
4+
chain when iterating over the properties of an object.
5+
6+
> **Note:** The `for in` loop will **not** iterate over any properties that
7+
> have their `enumerable` attribute set to `false`; for example, the `length`
8+
> property of an array.
9+
10+
// Poisoning Object.prototype
11+
Object.prototype.bar = 1;
12+
13+
var foo = {moo: 2};
14+
for(var i in foo) {
15+
console.log(i); // prints both bar and moo
16+
}
17+
18+
Since it is not possible to change the behavior of the `for in` loop itself, it
19+
is necessary to filter out the unwanted properties inside the loop body. In
20+
ECMAScript 3 and older, this is done using the [`hasOwnProperty`](#object.hasownproperty)
21+
method of `Object.prototype`.
22+
23+
Since ECMAScript 5, `Object.defineProperty` can be used with
24+
`enumerable` set to `false` to add properties to objects (including `Object`)
25+
without these properties being enumerated. In this case it is reasonable
26+
to assume in application code that any enumerable properties have been added
27+
for a reason and to omit `hasOwnProperty`, since it makes code more verbose and less
28+
readable. In library code `hasOwnProperty` should still be used since
29+
assumptions cannot be made about which enumerable properties might reside
30+
on the prototype chain.
31+
32+
> **Note:** Since `for in` always traverses the complete prototype chain, it
33+
> will get slower with each additional layer of inheritance added to an object.
34+
35+
### Using `hasOwnProperty` for Filtering
36+
37+
// still the foo from above
38+
for(var i in foo) {
39+
if (foo.hasOwnProperty(i)) {
40+
console.log(i);
41+
}
42+
}
43+
44+
This version is the only correct one to use with older versions of ECMAScript.
45+
Due to the use of `hasOwnProperty`, it will **only** print out `moo`.
46+
When `hasOwnProperty` is left out, the code is prone to errors in cases where
47+
the native prototypes - e.g. `Object.prototype` -
48+
have been extended.
49+
50+
In newer versions of ECMAScript, non-enumerable properties can be defined with
51+
`Object.defineProperty`, reducing the risk of iterating over properties without
52+
using `hasOwnProperty`. Nonetheless, care must be taken when using older
53+
libraries like [Prototype][1], which does not yet take advantage of new ECMAScript features.
54+
When this framework is included, `for in` loops that do not use
55+
`hasOwnProperty` are guaranteed to break.
56+
57+
### In Conclusion
58+
59+
It is recommended to **always** use `hasOwnProperty` in ECMAScript 3 or lower, as well as
60+
in library code. Assumptions should never be made in these environments about whether
61+
the native prototypes have been extended or not. Since ECMAScript 5, `Object.defineProperty`
62+
makes it possible to define non-enumerable properties and to omit `hasOwnProperty` in
63+
application code.
64+
65+
[1]: http://www.prototypejs.org/
66+

doc/bg/object/general.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Използване на обектите и свойствата им
2+
3+
Всичко в JavaScript действа като обект. Има само две изключения:
4+
[`null`](#core.undefined) и [`undefined`](#core.undefined).
5+
6+
false.toString(); // 'false'
7+
[1, 2, 3].toString(); // '1,2,3'
8+
9+
function Foo(){}
10+
Foo.bar = 1;
11+
Foo.bar; // 1
12+
13+
Често срещано погрешно схващане е, че числата не могат да бъдат използвани
14+
като обекти. Това се случва поради пропуск в синтактичния анализатор на
15+
JavaScript, който разбира точката като десетична запетая.
16+
17+
2.toString(); // в браузър хвърля синтактична грешка (SyntaxError)
18+
19+
Има три начина да се накарат буквално изписаните числа в програмния код също
20+
да действат като обекти.
21+
22+
2..toString(); // втората точка е разпозната правилно
23+
2 .toString(); // забележете оставеното място пред точката
24+
(2).toString(); // първо се изчислява изразът между скобите
25+
26+
### Обектите като тип данни
27+
28+
Обектите в JavaScript могат също да бъдат използвани като [*Хеш-таблици*][1].
29+
Те се състоят от именувани полета, сочещи към някакви стойности.
30+
31+
Обект може да се създаде като се използва буквално представяне. Новият обект
32+
[наследява](#object.prototype) от `Object.prototype` и няма [собствени
33+
полета](#object.hasownproperty).
34+
35+
var foo = {}; // нов празен обект
36+
37+
// нов обект с поле 'test', което има стойност 12
38+
var bar = {test: 12};
39+
40+
### Достъп до полета
41+
42+
Полетата (свойства) на даден обект могат да се ползват, като се използва точка
43+
(обект.именаполе) или чрез използване на квадратни скоби (обект['именаполе']).
44+
45+
var foo = {name: 'kitten'}
46+
foo.name; // kitten
47+
foo['name']; // kitten
48+
49+
var get = 'name';
50+
foo[get]; // kitten
51+
52+
foo.1234; // SyntaxError
53+
foo['1234']; // работи
54+
55+
Двата вида изписване работят по един и същи начин с единствената разлика, че
56+
когато използваме квадратни скоби, можем динамично да създаваме нови полета и
57+
да ползваме идентификатори, които иначе биха довели до синтактична грешка.
58+
59+
### Изтриване на полета
60+
61+
Единственият начин да се изтрие поле е като се използва операторът `delete`.
62+
Задаване на стойност `undefined` или `null` само премахва *стойността* на
63+
полето, но не и самото него -- *ключа*.
64+
65+
var obj = {
66+
bar: 1,
67+
foo: 2,
68+
baz: 3
69+
};
70+
obj.bar = undefined;
71+
obj.foo = null;
72+
delete obj.baz;
73+
74+
for(var i in obj) {
75+
if (obj.hasOwnProperty(i)) {
76+
console.log(i, '' + obj[i]);
77+
}
78+
}
79+
80+
Кодът горе показва `bar undefined` и `foo null` - само полето `baz` е
81+
изтрито и го няма в изхода на скрипта.
82+
83+
### Изписване на ключове
84+
85+
var test = {
86+
'case': '"case" е ключова дума, затова трябва да бъде оградена с кавички',
87+
delete: '"delete" също' // хвърля SyntaxError
88+
};
89+
90+
Свойствата (полетата) на обектите може да се изписват като обикновени низове в
91+
кавички или направо (без кавички). Поради друг пропуск в анализатора на
92+
JavaScript, горният код хвърля `SyntaxError` преди ECMAScript 5.
93+
94+
Тази грешка се получава, тъй като `delete` е *ключова дума*. В такива случаи
95+
полетата трябва да се изписват в кавички при ползване на по-стар JavaScript
96+
двигател.
97+
98+
[1]: https://bg.wikipedia.org/wiki/Хеш-таблица
99+

doc/bg/object/hasownproperty.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## `hasOwnProperty`
2+
3+
To check whether an object has a property defined on *itself* and not somewhere
4+
on its [prototype chain](#object.prototype), it is necessary to use the
5+
`hasOwnProperty` method which all objects inherit from `Object.prototype`.
6+
7+
> **Note:** It is **not** enough to check whether a property is `undefined`. The
8+
> property might very well exist, but its value just happens to be set to
9+
> `undefined`.
10+
11+
`hasOwnProperty` is the only thing in JavaScript which deals with properties and
12+
does **not** traverse the prototype chain.
13+
14+
// Poisoning Object.prototype
15+
Object.prototype.bar = 1;
16+
var foo = {goo: undefined};
17+
18+
foo.bar; // 1
19+
'bar' in foo; // true
20+
21+
foo.hasOwnProperty('bar'); // false
22+
foo.hasOwnProperty('goo'); // true
23+
24+
Only `hasOwnProperty` will give the correct and expected result. See the section
25+
on [`for in` loops](#object.forinloop) for more details on when to use
26+
`hasOwnProperty` when iterating over object
27+
properties.
28+
29+
### `hasOwnProperty` as a Property
30+
31+
JavaScript does not protect the property name `hasOwnProperty`; thus, if the
32+
possibility exists that an object might have a property with this name, it is
33+
necessary to use an *external* `hasOwnProperty` to get correct results.
34+
35+
var foo = {
36+
hasOwnProperty: function() {
37+
return false;
38+
},
39+
bar: 'Here be dragons'
40+
};
41+
42+
foo.hasOwnProperty('bar'); // always returns false
43+
44+
// Use another Object's hasOwnProperty and call it with 'this' set to foo
45+
({}).hasOwnProperty.call(foo, 'bar'); // true
46+
47+
// It's also possible to use hasOwnProperty from the Object
48+
// prototype for this purpose
49+
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
50+
51+
52+
### In Conclusion
53+
54+
Using `hasOwnProperty` is the **only** reliable method to check for the
55+
existence of a property on an object. It is recommended that `hasOwnProperty`
56+
be used in many cases when iterating over object properties as described
57+
in the section on [`for in` loops](#object.forinloop).
58+

0 commit comments

Comments
 (0)