Latest Updates: JavaScript RSS

  • Using Fiddler to help develop cross domain capable JavaScript web applications

    Phil Leggetter 10:08 am on 13th April, 2010 | 1 Permalink | Reply
    Tags: fiddler, JavaScript, Technology

    This post is going to be short and sweet. “Short” because Fiddler makes working around this problem so simple. And “Sweet” because I think this is really powerful and will allow you to develop applications that show why cross domain access, in some situations, should be allowed.

    In my last post on Making cross domain JavaScript requests using XMLHttpRequest or XDomainRequest I demonstrated that in order to access a resource (web page/web service) the server needs to respond to your application/JavaScript HTTP requests with an HTTP header of “Access-Control-Allow-Origin”. The problem arises when you are trying to access a resource that doesn’t presently send the required HTTP header, but you really need it to (I’ve addressed a similar problem to this when developing Silverlight applications and the solution, again, was to use Fiddler to trick Silverlight into allowing a crossdomain Web Request). For development purposes you’ll need to add the required header to the server HTTP response in your development environment. This is really simple using Fiddler.

    All you need to do is add a new custom rule. You can do this via the menu option: Rules -> Customize Rules…

    Fiddler Customize Rules option

    This will bring up a JScript.NET file (if you don’t like the thought of JScript you can just pretend it’s JavaScript) called CustomRules.js. In that file you will see a number of functions/methods that are called at certain points during an HTTP request or response. The method we are interested in is called OnBeforeResponse and what we want to do is to add the Access-Control-Allow-Origin header to trick the browser/scripting engine into thinking that the resource we are requesting allows the cross domain request.

    static function OnBeforeResponse(oSession: Session){	oSession.oResponse.headers.Add("Access-Control-Allow-Origin", "*");}

    (More …)

     
  • The banking exodus from IE6 begins?

    Patrick Myles 5:22 pm on 2nd March, 2010 | 1 Permalink | Reply
    Tags: , , , JavaScript,

    We’ve all seen the retail and consumer space push to ditch IE6 gathering pace over the last 6 months, including a petition to the UK government and Google’s announcement that their online productivity suite stopped supporting IE6 yesterday. But the corporates (and specifically banking)  have been a lot more reluctant to follow suit. But is this about to change?

    Rumour on the street has it that, finally, the investment banks are going to start abandoning IE6. Barclays are allegedly going to do an enterprise-wide rollout of IE8 in Q2 of this year (put back from Q3 last year). Even more surprising (and impressive) is a rumour that Standard Bank of South Africa are going to ditch Microsoft browsers completely and move to Chrome for their corporate standard!

     
  • JavaScript Variable Naming Convention

    Ian Alderson 4:05 pm on 10th February, 2010 | 0 Permalink | Reply
    Tags: JavaScript,

    When I joined Caplin 10 years ago I came from a company that used Hungarian notation to name its C++ and Visual Basic variables. For me, it seemed a natural progression to continue to use these naming conventions and adapt them to be suitable for the JavaScript code that I now writing.

    The evolution of software practices ebbs and flows over time, and it seems that Hungarian notation is currently out of favour. This is especially apparent with some of the new developers that have joined the team here at Caplin. One of the first questions they ask is often about the naming convention that we use.

    (More …)

     
  • Pitfalls of Exception expectations in JsUnit

    Ian Alderson 12:00 pm on 29th January, 2010 | 2 Permalink | Reply
    Tags: JavaScript, JsCoverage, , , ,

    At Caplin we use the JsUnit framework to test our JavaScript code. Over time we have made minor modifications to it, integrating Mock4JS and JSCoverage, as well as adding a few of our own extensions that are sympathetic to our JavaScript coding style, however, by and large, our tests are written using plain old JsUnit assertions.

    One of the main reasons we were keen to adopt JsUnit five years ago was its similarity to JUnit 3. Back then our developers had been using JUnit for a few years, and familiarity of the JsUnit API meant that we could immediately start writing tests. Unfortunately the old adage “familiarity breeds contempt” reared its ugly head, and we discovered that our main issue with JsUnit were the occasional, very subtle, differences between it and JUnit. The logic for a test that works in JUnit might not work in JsUnit.
    (More …)

     
  • Would a setMonth() by Any Other Method Name be as Sweet?

    Ian Alderson 11:28 am on 7th January, 2010 | 0 Permalink | Reply
    Tags: JavaScript,

    On 31st December 2009 a unit test that had been running successfully in the Caplin continuous integration environment for two months suddenly started failing.

    The test in question created a JavaScript Date object, modified it using various setter methods, then verified that the format method returned the expected value. The code for this is shown in the snippet below.

    var oDate = null;
    
    Test.setUp = function() {
       oDate = new Date();
       oDate.setYear(2012);
       oDate.setMonth(9 - 1);  // September
       oDate.setDate(8);
       oDate.setHours(17);
       oDate.setMinutes(05);
       oDate.setSeconds(19);
       oDate.setMilliseconds(55);
    };
    
    Test.format_Ext = function() {
       assertEquals("2012-09-08 17:05:19", oDate.format("Y-m-d H:i:s"));
    };
    

    (More …)

     
  • Supporting IE6 - a poison chalice or the holy grail?

    Patrick Myles 10:43 am on 14th July, 2009 | 6 Permalink | Reply
    Tags: , , , JavaScript, performance

    One of the big benefits of Caplin’s browser-based SDP platform, Caplin Trader, is that it can run in virtually any browser without the need for plugins or special configuration.

    This is no mean feat for a complex, high performance, low latency trading portal framework written in JavaScript and running to >250KLOC. Although IE8, Firefox, Safari and Chrome are similar enough to make it relatively straightforward to support each of them, IE7 and, particularly, IE6 are a different story. They are riddled with quirks and bugs in their layout, rendering and memory management engines. In addition, developer tool support is starting to lag. Worst of all, their performance is diabolical compared with the recent crop of competitors.

    However, IE6 is often one of our customers’ main target browsers by default. Sadly the big financial institutions, and to a lesser degree their clients, run with locked-down and often out-of-date desktop components. This limits their capacity to upgrade or install new browsers, though it’s true that some of the smaller firms are able to do so more easily.

    So, should we continue to support IE6? How should we encourage our customers and users to move to newer browsers? What are the benefits of doing so?

    (More …)

     
  • How to dynamically create a class definition for use with Mock4JS

    Phil Leggetter 6:00 pm on 16th April, 2009 | 1 Permalink | Reply
    Tags: , , JavaScript, , , ,

    Mock4JS is a really useful unit testing helper library that allows you to create mocks of your JavaScript classes. What it doesn’t presently support is mocking of objects that you can’t create an instance of yourself using new Class() or of objects that are dynamically created and have functions appended to them.

    (More …)

     
  • Adding an Observer to an Observable

    Ian Alderson 2:00 pm on 2nd March, 2009 | 1 Permalink | Reply
    Tags: , , JavaScript, Observer,

    The Observer design pattern is used in many applications. If you are unfamiliar with it, or need to remind yourself about the specifics, you can read about it at Wikipedia or MSDN. Caplin Trader even provides a helper class to take care of a lot of the boiler plate code: caplin.core.Observable.

    The purpose of the Observer design pattern is to allow one object to notify other objects of events – usually to do with changes to its state. One common problem I have encountered however is what to do when an Observer  is first registered, since the object that it is observing may already be in a particular state.

    (More …)

    Related Posts with Thumbnails