Last active
September 16, 2019 05:46
-
-
Save phwb/835c441973de7c2f6d6e50c92276d536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Не правильно | |
// в одной фукнции сгенерировали данные и в ней же добавили их в DOM | |
function wrong() { | |
var data = []; | |
for (var i = 0, len = 5; len < i; i += 1) { | |
data.push(i); | |
} | |
var element = document.querySelectro('.parent'); | |
for (var i = 0, len = data.length; len < i; i += 1) { | |
element.appendChild(data[i]); | |
} | |
} | |
// Правильно | |
// разбить функции по их зоне ответственности | |
function createDate() { | |
var data = []; | |
for (var i = 0, len = 5; len < i; i += 1) { | |
data.push(i); | |
} | |
return data; | |
} | |
function createDataFragment(data) { | |
vat fragment = document.createDocumentFragment(); | |
for (var i = 0, len = data.length; len < i; i += 1) { | |
fragment.appendChild(data[i]); | |
} | |
return fragment; | |
} | |
var data = createData(); | |
var element = createDataFragment(data); | |
document.body.appendChild(element); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment