Reference: Posts

Beware: object = object has a pitfall

So I spent an entire day discovering a quirk about javascript that I must now share. In a previous post on creating default settings for classes/objects I discussed the following technique:

JavaScript:
var Widget = new Class({
    initialize: function(element, options){
        this.element = element;
        this.options = Object.extend({
            offsetX: 0,
            offsetY: 0
        }, options || {});
        this.setPosition();
    },
    setPosition: function(){
        this.element.setStyles({
            left: this.options.offsetX + 'px',
            top: this.options.offsetY + 'px'
        });
    }
});

drag to resize


Now, this isn't a very useful class, but it illustrates the technique. The functions in our class don't have to worry if the options are defined; they are either what the default value is or they are what the user passed in. If the user elects to just pass in a subset of the values, that's fine:

JavaScript:
var myWidget = new Widget(myElement, {offsetX: 100});
//myElement will be offset by 100 on the left,
//zero (the default) on the top

drag to resize


But what if you want to extend the functionality of your class later? What if you want to be able to insert more default options?

Here's what I was doing that caused me trouble: | Read the rest »

Mootools r.83 cheat sheat

Just this morning I was pinging Valerio (author of Mootools) about a cheat sheet for Mootools after Snook posted his updated cheat sheet for Prototype 1.5. Funny thing; Snook posted a Mootools cheat sheet yesterday and it just hadn't gotten to my inbox yet. Go Snook! I'm going to add this to our cvs library along with all our other docs and whatnot.

In the same vein as the Prototype Cheat Sheet, I decided to go through and detail the Mootools library, as well. In comparison to Prototype, Mootools is definitely smaller and it's obvious they've put more focus on interactivity and decent DOM traversing.

I've colour-coded this one to match the four main categories that are in the download section of the web site and within the documentation. This way, it should hopefully be clearer when trying to compare against the two.

In going through things, I noticed that the documentation for Mootools isn't bad but spelling mistakes and what not have meant that a couple features aren't actually detailed in the documentation.

Anyways, for you Mootool luvin' fans, here are the cheat sheets:

Mootools Extentions Tutorial

Hi gang,

To go along with the posting of our collection of scripts, I'm still writing tutorials on how to make use of all our code. Today's update is for all our extensions to the Mootools libraries that we've written.

You'll find new helper functions, new extensions to ajax, string, element, window and more. For the most part, you can just drop these scripts into your environment and they should work. If there are dependencies, you can find them listed at the top of each script.

Mootools Primer, CNET Libraries online

Hi gang,

I've been at work on a mootools primer as a tutorial for those who want to use the library but don't know a lot about javascript. It's replete with working code examples that you can execute right in the browser and see the result. | Read the rest »

this.options - setting defaults that can be overwritten in your classes

Here's a trick I learned from Valerio (author of Mootools) on how to handle options for classes and functions. After refactoring a couple of legacy scripts I thought I'd share for those of you who might not know it already. This example below uses the Mootools syntax for class creation, but the rest of it can be used even on its own I think. | Read the rest »

Optimizing Page Load Time

via ajaxian (as usual):

Aaron Hopkins of Google has released an article on Optimizing Page Load Time which came out of his experience optimizing page load times for a high-profile Ajax application.

He starts off talking about "how much I could reduce latency due to external objects. Specifically, I looked into how the HTTP client implementation in common browsers and characteristics of common Internet connections affect page load time for pages with many small objects." | Read the rest »

javascript reference javadoc style

In relation to my previous post on the topic, I was digging around for javadoc options and stumbled upon this javascript reference in javadoc form. It's quick and easy to use like any javadoc and it's going in my bookmarks right now.

CNET Global Framework update

Hi all,

It's been a few days since I posted. I've been heads down on the project to create a global javascript framework for our sites (Redball, at least). I've finished this work (or at least gotten it to a releasable state) and I thought I'd share an update. I plan on documenting it extensively and providing a lot of examples (and teaching it) in the near future, but for those of you who are curious, you can peruse the library now. It's mostly stable (we're still tweaking and adding things) and you can just download them and read them if you want to see what's in them.

They include a lot of functionality, are highly extendable, easily debuggable, and hopefully will be useful. The current framework file is about 30K, but Andy just turned me on to a more efficient javascript compressor that will bring that down to 19K. I can't express how awesome it is to have this thing going out and it managing to pack in so much functionality in such a small package. | Read the rest »

First look: CNET (Redball) Global Javascript Libraries

I've been working on a global library for cnet javascript standards and I've got my first crack at it ready. I'm going to spend some time in the coming weeks working on documentation and examples, but for those of you interested, here's a quick look at what's in the collection. | Read the rest »

Some early blog posts on MooTools w/ examples

MooTools continues to impress me. Check out the Class.implement and Class.extend functionality in this great article from Cory Hudson (there are numerous code examples).

mootools implements a class inheritance scheme that is inspired by Dean Edwards' wonderful Base class. Creating a class is similar to Prototype, but now you don't ever have to think about the prototype object when you define the class...

...mootools supports multiple inheritance in a Ruby mixin style with the Class.implement() method. Using the implement method of an existing class, that class can inherit methods and properties from another class or object. Unlike Class.extend(), the implement method is called on the class you are modifying, not on the object being copied. This method can be used to support multiple inheritance.

And here's another article from Cory on MooTools numerous helpful utility functions:

The new mootools JavaScript framework has quickly impressed me with its design and usefulness. The library was clearly written to meet real programmers' needs while working in JavaScript. Just take a look at some of the new utility functions and methods it provides.

Note: This article covers functions and methods found in the Array.js and Function.js modules of mootools.

Categories

Archives

Links and whatnot