Javascript

Javascript method context

In languages like C# and Java you never really need to give a thought to the this operator. In javascript things are a little more complicated due to functions being first class objects.
Published in Javascript, Web development on Sunday, November 29th, 2009

Building javascript minification into MSBuild scripts

How to use a tool called Packer.NET to build javascript minification into a MSBuild script.
Published in ASP.NET, CSS, Javascript, Tools on Saturday, August 29th, 2009

Javascript prototype chaining

Prototype chaining is used to build new types of objects based on existing ones. It has a very similar job to inheritance in a class based language.
Published in Javascript on Monday, August 17th, 2009

Javascript object prototype

The javascript object prototype is javascript’s way of sharing implementation across similar objects, much like the way classes are used to do this in many other languages. Although constructor functions look a lot like classes, javascript does not have a class based object system like C# or Java. Instead it has a prototype based object [...]
Published in Javascript on Sunday, January 18th, 2009

Javascript null or default operator

A neat little trick I learnt from Ting is a way to check whether a value was null or undefined using the or operator (||). It’s really simple. If valueThatMightBeEmpty has a value set, you get that value. If it is null you get the default. It’s just like the ?? operator in C#: var value = [...]
Published in Javascript on Tuesday, December 9th, 2008

Javascript closures

Javascript closures are a really powerful feature of the javascript language. Closures are created when a function that’s nested inside another function accesses a variable from its parent’s scope. This is really useful for passing state around your application when the inner function is called after the outer function has exited. Javascript supports functions nested inside [...]
Published in Javascript, Web development on Friday, October 17th, 2008

Constructor functions

The object literal syntax is great for setting up one off objects but sometimes you’ll want to mass produce objects that all have the same properties and methods. It would be a pain to have to set up each object individually so instead you can use a constructor function to do it for you. There’s nothing [...]
Published in Javascript, Web development on Sunday, September 14th, 2008

Object oriented javascript slides and samples

I’m off to do a user group talk tomorrow night about object oriented javascript. :) Here are all the talk materials including slides, all samples and my list of bullet points I used to remind me what I wanted to talk about for anyone who went to the talk and wanted to take a look at [...]
Published in Javascript, My presentations, Web development on Sunday, August 31st, 2008

Javascript anonymous functions

Anonymous functions are functions that are dynamically declared at runtime that don’t have to be given a name. Anonymous functions are declared using the function operator. You can use the function operator to create a new function wherever it’s valid to put an expression. For example you could declare a new function as a parameter to [...]
Published in Javascript on Saturday, August 23rd, 2008

Functions are first class objects in javascript

Functions in javascript are first class objects. This means that javascript functions are just a special type of object that can do all the things that regular objects can do. Really, just like any other variable Here are a few of the important objects things that you can do with a function in javascript. A function is an [...]
Published in Javascript on Tuesday, August 19th, 2008

Building simple objects

Javascript objects are basically just hash tables, a group of related properties and functions that can be accessed by a key. Properties are dynamically added at runtime. Methods are just properties that happen to be functions. Building a simple object The simplest way to build objects in Javascript is by declaring a new variable of type object [...]
Published in Javascript on Sunday, August 17th, 2008

How javascript objects work

This is a series of articles about how to use the javascript language features to write object oriented type code. It's designed for people who are already sold on the idea of bundling functionality up into objects and want to know the javascript way of doing things.
Published in Javascript on Sunday, August 17th, 2008

The bleeding edge of web: querySelector() and querySelectorAll()

One thing coming up in the W3C selectors api spec are a couple of new methods for retrieving DOM elements called querySelector() and querySelectorAll() that take a css selector and return a node or list of nodes that match. They basically do the same thing as the css query features of JQuery or Dean Edward’s [...]
Published in Javascript on Saturday, July 12th, 2008

JSAN open source code repository

Learnt something new today! There’s a repository of open source javascript code called JSAN modelled on the perl version. There’s a whole lot of interesting stuff on there like UI widgets, animations and AJAX. I haven’t tried any but it’s nice to know there’s somewhere you can see what other people are doing.
Published in Javascript on Friday, May 2nd, 2008

Objects, event handlers and "this" in javascript

One recurring problem I’ve had when using a function from a custom javascript object as an event handler is that when the event handler is called the “this” property of the function no longer references the object it originally belonged to. To show you what I mean, take a look at this simple javascript object. It [...]
Published in Javascript on Saturday, April 26th, 2008

Spanning javascript strings across multiple lines

I came across a weird feature of javascript last week, a way of spanning javascript strings over multiple lines. To do it you put a ‘\’ character just before the line break and javascript knows it should keep going on the next line: var mystring = "hello \                world"; I found [...]
Published in Javascript on Sunday, May 13th, 2007

DIY javascript stack trace

How to use arguments.callee to walk up the javascript call stack when you're doing something that a debugger can't help you with.
Published in Javascript on Saturday, May 12th, 2007

Javascript lint – saviour of mortal developers

Something I really, really love at the moment is a little application called javascript lint. It’s a javascript syntax checker that’s built on top of the Mozilla javascript engine. You can run it over a javascript include file (I don’t know if it’ll work on inline javascript) and it’ll syntax check it for you without you [...]
Published in Javascript, Tools, Web development on Monday, February 5th, 2007

New link for IE drip memory leak detector

I found a link to a new page for the really useful drip tool which looks for IE memory leaks in javascript code. There’s also been a new revision of the program by the guy who’s hosting it.
Published in Javascript, Tools, Web development on Wednesday, June 28th, 2006

Bookmark: ASP.NET DataBinding internals

I found a very interesting article about ASP.NET data binding that talks about exactly what’s happening when you call the DataBind() method on a templated control like the repeater. It’s got some really interesting stuff on how the templates are instantiated and how the child controls are built.
Published in Javascript, Server controls on Monday, April 10th, 2006

Pausing page rendering at a certain point

I don’t know if this will be useful to anyone else but I thought this was kind of a neat trick for messing around with ASP.NET page rendering for debugging purposes. My problem was I wanted to stop the rendering of a page at a certain point so I could see how the scripts were reacting [...]
Published in ASP.NET, Javascript, Server controls on Friday, April 7th, 2006

UserControl type not available if code behind file isn't in app_code directory

I ran into a weird problem with dynamically created ASP.NET 2.0 user controls yesterday. I was using the user control to populate a panel of a tab control which meant I didn’t actually have a reference to the user control object anywhere on my form. The only way I could get a reference to it [...]
Published in ASP.NET, Javascript, Server controls on Thursday, April 6th, 2006

The Mozilla equivalent of CurrentStyle

IE has a pretty nice DOM property called currentStyle that you can use to find out the resolved style properties of a DOM object. This is neccessary because the style property will only tell you what style properties have been set, they won’t tell you what properties have been inherited from the element’s parent nodes. The [...]
Published in Javascript on Thursday, September 1st, 2005

JSLint: neat javascript script verifier tool

I found a useful little utility called Lint that checks for things in your javascript code that’s likely to introduce errors. I really like that it checks for undeclared variables because I always, always, always want to declare my variables before I use them. Considering that forgetting to declare the variable sets it global for the [...]
Published in Javascript, Tools on Monday, August 15th, 2005

Measuring element dimensions and placement in javascript

I found a really useful page on the MSN site that explains how measuring element dimensions and locations work in javascript. There’s a great image that shows you how to measure any of the different areas using the different javsacript width, height and placement properties.
Published in Javascript on Thursday, August 11th, 2005