coucou
Stop
ES2015
|
Before ES2015
|
byTagName = (node, tagName) => {
const found = [];
tagName =
tagName.toUpperCase();
_explore = (node) => {
for (let elt of
node.childNodes) {
if (elt.nodeType ==
document.ELEMENT_NODE)
if (elt.nodeName ==
tagName)
found.push(elt);
_explore(elt);
}
}
_explore(node);
return found;
}
|
function byTagName(node,
tagName) {
var found = [];
tagName =
tagName.toUpperCase();
function explore(node) {
for (var i = 0; i <
node.childNodes.length; i++) {
var child =
node.childNodes[i];
if (child.nodeType ==
document.ELEMENT_NODE)
if (child.nodeName ==
tagName)
found.push(child);
explore(child);
}
}
explore(node);
return found;
}
|
let tab = ["a","b","c"];
var printI = function(){
console.log(tab[i]);
};
for (var i=0; i<tab.length;i++){
setInterval(printI, 1000*(i+1));
}
|
let tab = ["a","b","c"];
var i; // i sera égal à 3 lors des appels
var printI = function(){
console.log(tab[i]);
};
for (i=0; i<tab.length;i++){
setInterval(printI, 1000*(i+1));
}
|
Remarque :
Examiner le code pour
class elHandler { constructor(el) { // pas de fx arrow this.el= el; this.init(); } init(){ this.el.addEventListener("click", event => this._action(event.type,this.el), false); return this; } _action = (type,el) => { console.log(` Handling + ${type} for ${el.id} `); el.classList.toggle("red"); return this; } }; var objDiv = new elHandler(document.getElementById("para1")); Et finalement
class elHandler { constructor(el) { // pas de fx arrow this.el = el; this.init(); } init() { this.el.addEventListener("click", function(event) { document.body.insertAdjacentHTML('beforeend', `<div id="two">this.ed = ${this.el}</div>`); this._action(event.type, this.el) }, false); return this; } _action = (type, el) => { el.classList.toggle("red"); return this; } };