JavaScript
JavaScript Prototypal Inheritance
Are you struggling to understand Javascript Prototypal Inheritance?
Andrea Giammarchi has written an article covering different aspects of it.
Contents
- Summary
- Object
- prototype basis
- Object.prototype … forbidden?!
- Classes and classical inheritance basis
- A better classical inheritance with an intermediate constructor
- Never forget the constructor property!
- Privileged properties and methods
- Private methods
- Private properties
- Protected properties and methods
- Anonymous instance as prototype
- Native constructors exception
- Classical inheritance patterns
- A better extend function proposal
- Some post it
I haven’t had time to read through it yet, but am pretty sure it will be a good read, there are lots of example snippets for you to look at to get a better understanding of the topic.
Enabling Read Access for Web Resources
I’ve been looking at the proposal by W3C to do cross domain request via the XMLHttpRequest object in Javascript.
Abstract
This document defines a mechanism to selectively provide client side cross-site access to a Web resource. Using either a HTTP header or an XML processing instruction (or both) resources can indicate they allow read access from specified hosts (optionally using patterns). When a pattern is used, one can also exclude certain hosts. For instance, allow read access from example.org and its subdomains with the exception of public.example.org.
Here’s an article by Kris Zyp with his thoughts on it.
http://www.json.com/2007/11/16/w3c-enabling-read-access-for-web-resources/
- It does not create any new vulnerabilities with existing servers. Cross domain XHR will always fail with existing servers until they have specifically added headers to define the access control. In other words it doesn’t add new vulnerabilities to the web, rather it allows those who want to add cross site access the ability to due it in a secure manner without hacks like JSONP or fragment identifier messaging.
- Both GET and POST can currently be executed cross site with scripts tags or form submission, so many threats such as CSRF and DOS already exist, the proposal does not introduce them.
- The proposal states that cookies should be removed from cross site requests. This will reduce the incident of cross site request forgery, and forces developers to use more secure explicit forms of authentication maintanence.
- Developers that allow cross site access still must ensure that they are not providing privileged information to sites that should not be accessing the information. Developers that allow POST and other modifying operations should take similiar precautions.
- This provides a fine-grained access control level. When servers define access control headers that allow cross site access, they can specify which web page domains are allowed to access their resources.
I welcome it, as there have been many times where I have needed to do cross domain requests.
MSN Protocol - Adobe AIR
Over the weekend I decided to try and make a successful authenticated connection to MSN using AIR, writing it in Javascript. I can tell you this, it’s been nothing but a pain. I am not sure if it’s due to my limited knowledge of the MSN Protocol, or just that it isn’t possible. I would like to think it was the former. I have been so close to just giving up on it.
There are various versions of the MSN Protocol, 15 being the latest one being used by clients. I believe 14 and 15 require extra / different things done to create a successful login connection, so I decided to go back to MSNP13, things seemed a little easier from what I have read. I played around with it again last night, and managed to get as far as sending a request to Nexus. At the moment it’s still a no go.
Here are a few great resources for understanding the MSN Protocol.
http://www.hypothetic.org/docs/msn/index.php
http://msnpiki.msnfanatic.com/index.php/Main_Page
I will probably post the source in the week, just so people who might be interested in how it’s done can get an idea.
ECMAScript 4
Recently I have been reading over the ECMAScript 4 language overview whitepaper to see what tasty things are in it. There are some really great features, one being able to create classes. Here is a real basic example…
// A property
var url;
// Constructor
function Website(_url){
url = _url;
}
// Getter
function get webURL(){
return url;
}
// Setter
function set webURL(_url){
url = _url;
}
}
// Lets extend it
class Feed extends Website {
var desc;
var feed;
function Feed(_feed, _desc){
desc = _desc;
feed = _feed;
}
function getFeed(){
return feed;
}
function getDesc(){
return desc;
}
}
…and running it the interpreter…
>> var website = new Website("http://blogs.pixeldepth.net/Peter/");
>> website.webURL
http://blogs.pixeldepth.net/Peter/
>> var feed = new Feed("http://blogs.pixeldepth.net/Peter/feed", “Recent posts");
>> feed.getFeed()
http://blogs.pixeldepth.net/Peter/feed
>> feed.getDesc()
Recent posts
Cool stuff, and it doesn’t stop there. I would recommend checking out John Resig’s blog, he has been posting about ECMAScript alot lately. Here are his slides from one of his talk…
For more info, have a read of John’s blog…
Javascript AIR Samples
If you learn best by reading code, then I encourage you to download Kevin Hoyt’s examples. The zip file contains samples ranging from writing / reading files, to connecting to a database (SQLite).
“Revisiting 35+ samples for Beta 2 required a substantial amount of focus and time. As the next release of AIR hits the stands, I’m sure I’ll be required to find the time to update them once more. The good news is that I’m working on an easier way to share the samples, and allow for the community to get involved. I envision a place in the near future where you can add your own samples, comment on existing samples, and even rate them. Stay tuned!”
http://blog.kevinhoyt.org/2007/10/25/javascript-air-samples-updated/
AIRPacker
Yesterday and today, I have been working on an Adobe Air application that makes use of Dean Edwards Javascript Compressor called “Packer“. I found myself using Packer more and more often, and it was becoming a bit of a pain loading up the page, copy and pasting my Javascript in, and then creating the compressed file. Most of the time I ended up closing the page by mistake. Anyway, I wanted my own lazy way of doing it, so I set out to create an application that could open and save out files.
So with permission from Dean (thanks Dean) to use his Packer script, I give you AIRPacker…
As you can see, the layout is basically the same as what is on the Packer page. Most of my time was spent learning the AIR API.
At the moment it has only been really tested on Windows, I don’t have access to a Mac at home, so let me know of any problems.
To run the application, you will need Adobe AIR.
Install from your browser…
Here is the AIR file…
Note: This is a beta.
If anyone wants the source, just open it up with winrar and extract the contents. Or I could upload a zip file if people want it.
Any problems, please post a comment.
Ext JS - 2.0 Beta
If anyone is thinking about creating slick applications in the browser, or even thinking of creating something with Adobe AIR, then I highly suggest you take a look at Ext JS 2.
Ext JS is a GUI library that has tons of components, comes with excellent documentation, tutorials, and a community.
I have used Ext JS now and again for personal projects, mainly using it for developing desktop applications using Adobe AIR, and will likely continue to use it.
Have a look at this desktop example application in your browser (note: if you have firebug, disable it, or you may find it is a little slow)…
http://extjs.com/deploy/dev/examples/desktop/desktop.html
Check the main site out…
Easing Equations
At work I have been writing an Fx class in Javascript for a component that will be used on one of our clients websites. While writing the Fx class, we (work team) decided that easing effects would be needed to give it that nice feel too it. While researching easing, I came across a website that had Actionscript easing equations, and now looking at some of the Javascript frameworks out there, they have also used the equations. It seems that Robert Penner’s equations are extremely popular, and best of all, extremely easy to implement into Javascript.
Here is Robert Penner’s website…
http://www.robertpenner.com/easing/
I have implemented most of the easing equations into our Fx class, though we were mainly interested in the Back class, done some testing, and found they work extremely well.
So if you are thinking of writing your own Fx class, I highly suggest looking at Roberts equations, they seem to be the standard.
Scollovers
Nice little script someone has put together to create scollover effects. Have a look at the link below for an example and source…
Javascript 1.8
I haven’t really been following the progress of this, mainly because other browsers haven’t caught up with Firefox yet, but it’s interesting to see what will be in 1.8.
John Resig goes over the 3 main features…
What Am I Doing?
- Installed W@W 1.02 patch, should now be able to play with American friends, let the desync commence
- Just finished playing World at War, can now connect to people. Spawning is really bad, a very high chance of being shot in the back.
- Still can't connect to anyone on World at War multiplayer, but people can connect to me, very annoying.
- Finished Call of Duty World at War single player, felt shorter than Modern Warfare. Now I can play Zombie mode.
- Played Call of Duty World at War, at the moment I'm not keen on it, WWII doesn't do it for me. I'll keep playing, might start to like it.
- Yay, I got news that Call of Duty World at War has been delivered from Game.
- Just finished playing Call of Duty 4, which could be the last time, as W@W should arrive tomorrow.
- At work
- Played some CoD4 before work, my team was really bad
- Downloading Ubuntu, Vista is horrible to develope on
- On my way home through the lovely rain on my bike
- Completed Far Cry 2 at the weekend
- Installed Twinkle app on touch, awesome for a free app
- Setting up Twitter on my Ipod Touch
Search
Categories
- Browsers (14)
- Gaming (19)
- General (103)
- ProBoards (12)
- Programming (97)
- Adobe AIR (18)
- JavaScript (37)
- pDBB (8)
- PHP / MySQL (9)
- PHP-GTK (4)
- Videos (16)
- Work (4)
Recent Comments
Tags
2032 actionscript adobe africa alive air airpacker browser cod COD4 css dean edwards ds easing eric schmidt error explorer ext facebook file Firefox flickr Gaming google htaccess ie input internet JavaScript mime nintendo packer penner perl pleasurewood hills poignant PS3 robert ruby safari scrollovers testing theme park wii wordpress xboxArchives
- October 2008 (6)
- September 2008 (3)
- August 2008 (2)
- June 2008 (4)
- May 2008 (2)
- April 2008 (1)
- March 2008 (5)
- February 2008 (3)
- January 2008 (1)
- December 2007 (3)
- November 2007 (6)
- October 2007 (5)
- September 2007 (13)
- August 2007 (7)
- July 2007 (5)
- June 2007 (9)
- May 2007 (17)
- April 2007 (10)
- March 2007 (19)
- February 2007 (27)
- January 2007 (19)
- December 2006 (4)
- November 2006 (4)
- October 2006 (15)
- September 2006 (14)
- August 2006 (12)
- July 2006 (9)
- June 2006 (12)