Archive for June, 2008

My Master’s Thesis

It was almost a year ago when I graduated from Gdansk University of Technology, major Distributed Applications and Internet Systems. The title of my Master’s Thesis was “Social Semantic Information Sources for eLearning”. All in all, I forgot to present the thesis… So, here it goes :)

Master's Thesis.

You can also download the thesis from Library@DERI.Galway. Apart from that, you can find there more papers of mine on Library@DERI.Galway.

Share and Enjoy:
  • del.icio.us
  • Digg
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

Microsoft JScript runtime error: Object doesn’t support this property or method.

Yesterday I spent two hours analyzing this issue, which of course I had only with Internet Explorer…

As the background: I wrote a library that would make a table sortable and paginable. I decided to use prototype.js and script.aculo.us. I tried to test the result not only in Firefox which I use by default, but then I simply forgot… Then, when I run the page I got the error:

Microsoft JScript runtime error: Object doesn’t support this property or method.

At the end of the day, (after cutting JavaScript files into slices) I found the reason. All because I created HTML elements like follows (this example uses Builder of script.aculo.us):

$(this._sPaginationSecId).appendChild(Builder.node('span', { class: 'disabled' }, '<'));

If you look at that closer, you will find out that class is not put inside apostrophes (’).

Important!
Be careful with defining properties like href and class with Builder.node() (of script.aculo.us) and new Element() (of prototype).

Share and Enjoy:
  • del.icio.us
  • Digg
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

JavaScript: what if nested ‘this’ doesn’t work?

Note: Examples used in that post require usage of prototype.js.

Imagine you have a JavaScript class with some features related to the current view. One of the method in that class is supposed to add an observer on all anchors marked with class “delete”. That observer is also defined in this class. In other words, you have a number of “delete” links (similar to one below) and you want to register an event handler that would fire when either of those links is clicked.

The link exmple:
<a href="#" class="delete">delete</a>

Let’s assume the aforementioned methods are defined as follows:

registerDeleteHandlers: function() {
	$$('a.delete').each(function(anchor) {
		anchor.observe('click', this.deleteItem);
	});
},

deleteItem: function(event) {
	...
}

As you would discover the handler wouldn’t be registered… It’s because this inside the inner function (which really registers the observer) is binded to a different context!

Simple solution (smarter)

Define the registerDeleteHandlers function as follows:

registerDeleteHandlers: function() {
	$$('a.delete').each(function(anchor) {
		anchor.observe('click', this.deleteItem);
	}.bind(this));
}

Another way around

Inside the registerDeleteHandlers function you can bind this to a temporary variable and use it in the inner function instead of this. So the registerDeleteHandlers function would look like that:

registerDeleteHandlers: function() {
	var self = this;
	$$('a.delete').each(function(anchor) {
		anchor.observe('click', self.deleteItem);
	});
}
Share and Enjoy:
  • del.icio.us
  • Digg
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail