25 May 2007
Unicode UTF-8 Byte Order Mark
So, I setup this site with the intent of focusing on internationalization and localization as they relate to the web but have not done a whole lot of that yet. I have found that this is something I actually know more about just because I have developed in a multilingual (English, Chinese, Japanese) environment for a while. To kick this off, I thought I would put up a short blurb about the Unicode UTF-8 Byte Order Mark, otherwise known as the BOM. If you have ever seen  prefixing the first line of a file, then you have already been introduced. My thought here is not to discuss the nature of the BOM (you can check out the links below) but to mention some potentially lesser known facts about its use that developers may run into.
- When saving a file in Notepad, if you save with "Encoding" set to "UTF-8" then you are including the BOM at the beginning of the file even though you cannot see it. Similarly, in Visual Web Developer, if you save the file with encoding and choose "Unicode (UTF-8 with signature) – Codepage 65001" then you are also including the BOM at the beginning of the file.
- Properly using multilingual text on the web requires using files saved with Unicode encoding. There are usually a number of options. Generally, best practice is to not include the UTF-8 BOM, and I recommend choosing a Unicode encoding that both excludes the BOM and maintains a small file size. For example, in Visual Web Developer, I save files with the "Unicode (UTF-8 without signature) – Codepage 65001" encoding.
- Having said that, I ran into the same case twice on my former blogging platform where I was forced to include the BOM at the beginning of an ASP file in order for it to properly recognize the script as Unicode and correctly process Unicode text. If all else seems to be failing, give it a shot and see if it fixes it. Still, my recommendation is to exclude the BOM unless it proves absolutely necessary.
Check out these links for more information:
20 May 2007
Object-Oriented JavaScript and setTimeout
Here are two examples of how to use setTimeout in an object constructor with public methods added to the prototype. Functions called using setTimeout are executed in the scope of the window object, so the this keyword does not apply. In both of these examples, clicking on a link triggers an alert after a pause of two seconds. In the first example, the alert function and the setTimeout are both in a public method of the object instance. In the second example, the setTimeout is in one public method while the alert is in another.
var myObject = function(myArgument) {
this.myProperty = myArgument;
this.myTrigger = document.getElementById('myLink');
this.init();
};
myObject.prototype.init = function() {
this.myProperty = 'New Value';
YAHOO.util.Event.addListener(this.myTrigger, 'click', this.myMethod, this);
};
myObject.prototype.myMethod = function(e, obj) {
var myFunction = function() {
alert(obj.myProperty);
};
YAHOO.util.Event.preventDefault(e);
setTimeout(myFunction, 2000);
};
new myObject('Initial Value');
var myObject = function(myArgument) {
this.myProperty = myArgument;
this.myTrigger = document.getElementById('myLink');
this.init();
};
myObject.prototype.init = function() {
this.myProperty = 'New Value';
YAHOO.util.Event.addListener(this.myTrigger, 'click', this.myMethod1, this);
};
myObject.prototype.myMethod1 = function(e, obj) {
YAHOO.util.Event.preventDefault(e);
setTimeout(function() { obj.myMethod2(); }, 2000);
};
myObject.prototype.myMethod2 = function() {
alert(this.myProperty);
};
new myObject('Initial Value');
4 May 2007
Literal Notation and Object Constructors in JavaScript
Putting something up here again for my own reference. The comments on this article are the part that interested me. I like using object literal notation and wanted to know if it would be possible to write a reusable object constructor in literal notation. From all the discussion, it seems that making object constructors is best still done using a prototype function. Object literal notation is great for creating a single instance of an object but not ideal for creating an object constructor that can be used to create multiple instances of an object. If anyone knows differently, I'd be interested.
Edit: Here are two sites that offer utilities to create constructor classes from an object in literal notation:
2 May 2007
YUI Library Review
Throwing this up here partly for my own reference.
AJAX: Selecting the Framework that Fits
Reviews five JavaScript libraries (Dojo, Prototype/Scriptaculous, Direct Web Remoting, Google Web Toolkit, and the Yahoo! User Interface Library) and evaluates them on a couple categories. Article picks the YUI library. Glad I use and am a part of that one. It's one of Yahoo's strongest points in my opinion. Check it out if you are looking for a JavaScript library:
20 December 2005
Allegory, Myth, and The Chronicles of Narnia
Like most life-long readers of The Chronicles of Narnia, I am really looking forward to the release of The Lion, the Witch and the Wardrobe in December. I used to do my homework on C.S. Lewis' desk in the afternoons during my first year at Wheaton and thought it was the coolest thing ever (before it became a dead museum piece in the new Wade Center). Needless to say, the commercialization of the story is painful to watch. People in malls promoting the movie dressed like lions. Action figures in production and probably a video game at some point. CCM artists using the Narnia tag to try and sell their music to the mainstream. I concede that the hype offers the Church a unique opportunity to share the story with moviegoers, but I hope that those who go searching for a reading of The Chronicles this Christmas do not settle for a poor one. One distinction I find to be particularly powerful in the books separates allegorical representation from the symbolic genre that C.S. Lewis sometimes labels "myth". To further employ this terminology, the symbolism of The Chronicles of Narnia is not allegory but "incarnated myth".
What is the difference? To clarify this distinction with the example at hand, allegorical writing would examine the New Testament account of the salvation of our world and ask, "How can the historical facts of this story be retold in the land of Narnia?" or "What can we use to represent the characters of Christ, Satan, Judas, and Mary?" Myth, on the otherhand, perceives a reality and truth that transcends space and time and asks, "How would this truth that has entered into the history of our world in a particular way make itself manifest in the world of Narnia?" Allegory supposes Narnia to be a direct representation or copy of our own world. Incarnated myth supposes Narnia as a parallel world subject to the same higher order. In The Chronicles, it is made clear that Narnia's story is not meant to be a mere retelling of the story of our world. Both worlds exist side-by-side in the books and have independent histories that interact at times. Ultimately, this is most apparent at the close of The Last Battle where the two worlds are brought together into a common deeper reality.
In a letter to a fifth grade class in the United States, C.S. Lewis once wrote, "You are mistaken when you think that everything in the books 'represents' something in this world. Things do that in The Pilgrim's Progress but I'm not writing in that way. I did not say to myself 'Let us represent Jesus as He really is in our world by a Lion in Narnia': I said 'Let us suppose that there were a land like Narnia and that the Son of God, as He became a Man in our world, became a Lion there, and then imagine what would happen.' If you think about it, you will see that it is quite a different thing."
Why is the distinction important? As incarnated myth, The Chronicles allow Lewis more freedom and imagination with the story, instead of demanding that everything directly correlate with some part of the New Testament chronology. Besides allowing the author more freedom though, the use of incarnated myth as opposed to allegory is also one of the things that makes The Chronicles uniquely powerful. Instead of being a symbol that is only relevant within the borders of the story, Aslan is a character that is not intended to represent Christ but is supposed to actually be the person of the Son of God in Narnia. Aslan's sacrifice in The Lion, the Witch and the Wardrobe may remind readers of the crucifixion and resurrection, his roles as creator and king in the other books may further reinforce the correlation, but ultimately it is at the end of The Last Battle that it becomes clear he is more than a symbol. "And as He spoke He no longer looked to them like a lion." As the form of the lion fades, the focus is directed towards his person, and we discover that he has always been present and active in the histories of both Narnia and our world.
By suggesting that C.S. Lewis means for Aslan to be the second person of the Trinity made incarnate in the Narnian world and not an allegorical representation of the man Jesus Christ, I am not trying to advocate a dualism that tears transcendent spiritual reality from the gospel of history or favors one over the other. Elsewhere he writes, "As myth transcends thought, Incarnation transcends myth." The power of The Chronicles is amplified by the realization that the eternal Son of God we cannot help recognizing in the person of Aslan did become a man at a specific time in history. He was born into our world. He died bearing our sins and then rose again. He reigns forever as our King. The power of The Chronicles and the story of Christmas lie together there. The Myth become fact. The Word made flesh.