mcottondesign

Loving Open-Souce One Anonymous Function at a Time.

Technical questions

Here are some interview questions, when I'm back from vacation I'll have proper examples

write out a dog class in JavaScript with a color property and a bark method


var Dog = function(color) {
this.color = color;
this.bark = function() {
console.log('woof');
}
};

If I wanted to create a new dog

var clarence = new Dog('black and white');

and if I wanted to add an eat method to the Dog class. This is will add it for all previously defined instances of the Dog class.


Dog.prototype.eat = function() {
console.log('yum yum yum');
};

jQuery.live() vs jQuery.delegate()


$('#profs li').live("click", function() {
alert('clicked');
});

vs


$('#profs').delegate("li", "click", function() {
alert('clicked');
});

They both provide the same functionality, but the difference is that live() attaches to the document.

implement jQuery.delegate() in pure JavaScript


function doSomething() {
alert('click');
}


ul = document.getElementById('profs');
ul.addEventListener('click', doSomething, false);

I didn't know the syntax for addEventListener(). Once I looked that up it was extremely simple.

custom event listeners in JavaScript

This is another one I needed to look up. I'll need to look at it more to understand it better. Unfortunately it is different in Node.js, socket.io, and CouchDB.