3. Recap
var data = [[0, 1, 2, 3], [4, 5], [6, 7, 8, 9]]
;
for (var x = 0; x < data.length; ++x) {
for (var y = 0; y < data[x].length; ++y) {
console.log(data[x][y]);
}
}
Friday, 18 October 13
4. Recap
var el = document.getElementById('output');
el.id;
el.className;
Friday, 18 October 13
5. Recap
var el = document.getElementById('output');
el.setAttribute('lang', 'en');
el.getAttribute('lang');
// <div id="output" lang="en"></div>
el.setAttribute('data-foo', 'foo');
el.getAttribute('data-foo');
// <div id="output" data-foo="foo"></div>
Friday, 18 October 13
6. Recap
var el = document.getElementById('output');
el.addEventListener('click', callback, false); // not IE
< 9
el.attachEvent('onclick', callback); // IE < 9
Friday, 18 October 13
7. Recap
var el = document.getElementById('output');
function callback(e) {
alert('hello world');
e.preventDefault();
e.stopPropagation();
}
el.addEventListener('click', callback, false);
Friday, 18 October 13
19. Classes
function Animal(name, sound) {
this.name = name;
this.sound = sound;
}
dog = new Animal('fido', 'woof!');
cat = new Animal('puss', 'meow!');
dog.name // fido
cat.name // puss
Friday, 18 October 13
20. Classes
function Animal(name, sound) {
this.name = name;
this.sound = sound;
}
Animal.prototype.greet = function() {
console.log(this.sound);
}
dog = new Animal('fido', 'woof!');
cat = new Animal('puss', 'meow!');
dog.greet();
cat.greet();
Friday, 18 October 13
21. Classes
function Dog(name) {
this.name = name;
this.sound = 'woof!';
}
Dog.prototype = new Animal(null, null);
dog = new Dog('fido');
Friday, 18 October 13