This is a video I found on YUI Theater. If you have spent any amount of time with javascript especially event handling and especially event handling within input fields you’ve driven yourself to the point of insanity on at least one occasion. I am not so sure if this video helps as much as it just shows you how different the implementations are.
New Site
07.04.2009Yep, it was about time for a change. I set out this morning to design a new site. I was using a theme before for my personal blog and I had a seperate site for my freelance business. Well, I am dropping the freelance and I am switching everything over to my personal site.
From here on out, I will be publishing selected freelance work and some various programming explorations.
I hope you enjoy.
-Josh
Javascript prototype linkage “Wierdness”
07.01.2009The way object linkage works in javascript is through “prototype”. Prototype is a dynamic linkage between objects. If we look for a property of an object and it doesn’t exist, the next thing it will try and do is step backwards in the prototype linkage and find a match before returning undefined.
Here’s where it gets tricky. If your initial object has a property set, and the object it inherits from overwrites that property that is all well and good. But, what if you decide later to delete that property from your new object? You would think an attempt to access it would return undefined right? Wrong. You are back at square one looking back up the prototype chain. Take a look.
-
-
var foo = function() {}
-
-
foo.prototype.setBikeColor = function(color) {
-
this.bike = color;
-
}
-
-
-
foo.prototype.bike = "red";
-
-
var bar = new foo();
-
-
alert(bar.bike); //Alerts ‘red’
-
bar.setBikeColor("blue");
-
alert(bar.bike); //Alerts ‘blue’
-
delete(bar.bike);
-
alert(bar.bike); //Alerts ‘red’
-
The linkage is always there. It is always dynamic. And you can’t delete ‘bike’ from the objects prototype either because you then run the risk of deleting it from everyone.
