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.

http://www.3site.eu/doc/

Tags: , ,

Tuesday, March 25th, 2008 JavaScript, Programming No Comments

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.

Tags: ,

Wednesday, November 21st, 2007 JavaScript, Programming No Comments

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.

Tags: , , ,

Tuesday, November 20th, 2007 Adobe AIR, JavaScript, Programming 3 Comments

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…

class Website {

   // 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…

>> intrinsic::load("tests/test.es");
>> 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…

http://ejohn.org/blog/

Tags: ,

Saturday, November 10th, 2007 JavaScript, Programming 3 Comments

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/

Tags: , ,

Thursday, October 25th, 2007 Adobe AIR, JavaScript, Programming 2 Comments

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…

packer1.jpg packer2.jpg
packer3.jpg packer4.jpg

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…

AIRPacker

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.

Tags: , , , , ,

Monday, October 22nd, 2007 Adobe AIR, JavaScript, Programming 2 Comments

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…

http://extjs.com/

Tags: , , ,

Friday, October 12th, 2007 Adobe AIR, JavaScript, Programming 2 Comments

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.

Tags: , , , ,

Wednesday, September 12th, 2007 JavaScript, Programming, Work No Comments

Scollovers

Nice little script someone has put together to create scollover effects. Have a look at the link below for an example and source…

http://www.scrollovers.com/

Tags:

Friday, August 10th, 2007 JavaScript, Programming No Comments

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…

http://ejohn.org/blog/javascript-18-progress/

Tags:

Wednesday, May 30th, 2007 JavaScript, Programming No Comments

What Am I Doing?

Search

 

Categories