Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin

Intel Core i7 920 - Initial Thoughts, Overclocking and Windows Vista

I recently upgraded my main desktop machine to a new Intel Core i7 920 CPU and all its glory. Here's a write up of my experience in choosing the Core i7 (over the Core 2 Quad) and my experiences with it so far.

Thoughts Before Upgrading - Core 2 Quad or Core i7?

My previous machine was an AMD Athlon 64 X2 4200+ (2.2Ghz) with 4GB DDR2 800Mhz Ram. The system ran great, but it was two years old and my requirements for using Virtualization (via Virtual PC) have increased so it's time for an upgrade.

I was looking to build a Quad Core machine, and was originally looking at the Core 2 Quad, but then I found out that the new Core i7 was coming out Nov. 17. So, I waited, read the pre-release reviews, got more interested, waited, and finally purchased on Nov. 17. There are three versions of the Core i7 out right now, the 920 (2.66Ghz, $300), 940 (2.92Ghz, $570) and 965 (3.2Ghz, $1,050).

Originally, I was looking at spending ~$300 for the Core 2 Quad Q9550 (2.83Ghz). But, after reviewing the data on the new Core i7, things looked promising that the 920 would perform better, and for the same price.

Thoughts During/After Upgrade

In this upgrade I replaced the Motherboard (Gigabyte GA-EX58-UD5, $298.99), CPU (Intel Core i7 920, $319.99) and Ram (G.SKILL 2 x 2GB DDR3 1600, $149.99).

The Core i7 supports Triple Channel DDR3 memory. What this means is you need to have 3 or 6 (multiples of 3) Ram sticks in order to run in Triple Channel. If you only have 2 Ram sticks you can run in Dual Channel mode; this is what I'm doing currently.

DDR3 Ram Advisory: It has been reported in various sources online, that the Core i7 CPU can be damaged by DDR3 Ram that operates at higher than 1.65v. You need to be aware of this when purchasing memory. If you look the G.SKILL memory I have listed above has a rating of 1.8v on NewEgg. I ordered this memory before I found out about this limit, but luckily the 2 sticks I got are actually rated at 1.5v.

After installing the hardware, I booted up Windows Vista x64 (I didn't reinstall, still booting off the old hard drive. Windows Vista took a little bit to catch up, since it needed to install all new drivers for the major upgrade in hardware. After about 2 minutes all drivers were updated and Vista booted up ready for login.

Running Vista on the new Core i7 920 (stock settings), things seem snappier than they did on the old system. The Windows Experience Index for the Processor is 5.9, up from 4.9 for the Athlon 64 X2 4200+.

Here's a screenshot of my Windows Experience Index with the Core i7 920 and 4GB Ram at "stock" settings:

Update: After originally posting this I found out that the highest Windows Experience Rating under Vista that any component can score is a 5.9. Until I found this out, I was curious as to why the Core i7 920 running at 2.6Ghz scored the same as running at 3.4Ghz. I wonder how high the Core i7 CPU's would score if Vista were able to give a score higher than 5.9? I also wonder what the max Windows Experience Index Score will be in Windows 7 when if comes out.

And for comparison, here's the Windows Experience Index for the old Athlon 64 X2 4200+ with 4GB Ram: 

Note: The reason the Graphics Score (and ultimately the Base Score) are so low is because I'm still using my old NVidia GeForce 6600 (256MB) Video Card; which I am thinking of upgrading soon to.

Overclocking the Core i7 920!

This is probably the most interesting part of this post; what you're really interested in, right?

The Core i7 has a couple changed to its architecture. First, it has an integrated memory controller on the chip with it's own clock multiplier. Second, there's a new clock multiplier called QPI. QPI ends up being the frequency that the indivisual CPU Cores talk to each other with. And then there's the Base Clock and the main CPU Multiplier. You can changed each of these four settings independently, essentially giving you more control when overclocking. 

The most notable thing is the 920 has a CPU Multiplier of 20 ("fixed"). This means you can't set it higher than that. The 940 also has a locked multiplier (at 22 I think). But, the 965 has an unlocked multiplier; this is meant to be the "ultimate" overclockers chip.

You can read more about the Core i7's architecture in other sources; I just wanted to give a brief, basic overview of what relates to the overclocking I've done.

Since there are so many things that can be adjusted, as well as voltage; you may be a little confused as you how you might go about overclocking it. Well, it's actually rather simple. For simple overclocking, all you need to do is adjust the Base Clock and everything else will follow along. It would be nice if you could adjust the CPU Multiplier, but you can only increase that if you have the 965 cpu.

The Core i7 920 at 2.66Ghz has a Base Clock of 133Mhz by default. One thing noting for comparison to my overclocking results is in my configuration the Max CPU Temperature at 100% load was 84c.

I've tested mine at both 2.92Ghz (146Mhz Base Clock) and 3.0Ghz (150Mhz Base Clock) using the Stock Cooler that come with the CPU, and both run very stable and seem to keep within safe temperatures; 86c max under 100% cpu load in my initial testing. Note, I do have 2 case fans, so I would recommend you have at least one good case fan for this.

I have tested the 920 at 3.2Ghz by setting the Base Clock to 160Mhz, but the temps got up to 90c under initial tests of 100% cpu load, so I set it back down to be safe. I added another small case fan and now it seems I'm able to get 3.2Ghz running without worrying about the temp. In initial testing, under 100% cpu load it's reached 88c max, and runs extremely stable.

I also tested the 920 at 3.4Ghz by setting the Base Clock to 170Mhz. In initial testing, under 100% cpu load it's reached 89c max, and runs extremely stable. 

I also decided to check out some benchmarks, so I ran CINEBENCH 10 with both 3.0Ghz (150mhz Base Clock), 3.2Ghz (160mhz Base Clock), and 3.4Ghz (170Mhz Base Clock):

CINEBENCH 10, x64 version, 800x600 Image

Core i7 920 @3.5Ghz (175Mhz Base Clock) - Score: 20,929.0

Core i7 920 @3.4Ghz (170Mhz Base Clock) - Score: 20,530.0

Core i7 920 @3.2Ghz (160Mhz Base Clock) - Score: 18,914.0

Core i7 920 @3.0Ghz (150Mhz Base Clock) - Score: 17,377.0

Core i7 920 @2.6Ghz (133Mhz "stock" Base Clock / My Configuration) - Score: 16,256.0

I haven't run CINEBENCH 10 on the "stock" settings on my machine, but here's an article that shows the 920 score 15,211.0 with "stock" settings. Since, posting this I decided to run the CINEBENCH 10 test on my configuration with the Core i7 920 at "stock" settings, and the results I got are actually higher than the ones in the previously mentioned link. With my "stock" settings scoring 16,256; that only makes my configuration run 2,085 points lower than the stock Core i7 965 mentioned in this article. According to the article the 965's highest score on "stock" settings is 18,341.0. That's 2,189 points lower than my overclocked 920 at 3.4Ghz.

A ~27% overclock isn't too bad on the stock cooler. Not to mention the fact that the Core i7 920 costs less than 1/3rd of the Core i7 965! 

Also, I need to do further testing to be confident with my results to be confident their safe. So just be careful when overclocking, and there's no guarantee all 920 chips will perform the same as mine. Happy Overclocking!

Overclocking Ram Advisory: As mentioned above the Core i7 requires memory that runs at or below 1.65v, otherwise (according to reports from various sources) it can damager the CPU. One thing to remember when overclocking the Core i7 is you may need to lower the RAM Multiplier in the Bios if you are trying to give the CPU a healthy overclock. In my case (using the G.SKILL Ram listed above) the Ram I have seems to run at 1.7v at 1600Mhz (which was stable for days); so just in case I decided to lower my Ram Multiplier so it runs lower, and wit the 3.4Ghz overclock the ran is running at 1.63v.

Does Windows Vista Fully Utilize the Core i7?

I'm not sure Windows Vista x64 can fully utilize this CPU yet. When I run Prime95, the CPU goes to 100%, but the Intel Speed Step Technology never bumps up the speed. It always remains at 1.7Ghz when set to stock settings. However, when I run the Window Experience Index test, the Speed Step kicks in and bumps it up to the full 2.66Ghz.

Update 11/27, all of a sudden, now my CPU always runs at full speed. It doesn't downclock itself to 1.7Ghz anymore. I don't think I changed anything in the BIOS that affects this, but I need to double check. My thoughts are also that this was some kind of burn in protection built into the CPU, but I haven's seen/read anything that mentions this.

I'll need to look further into this...

Future Thoughts

Since I am using Virtualization more, I'm looking to up my Ram from 4GB to 6GB or 8GB. You need more Ram when you run multiple OS's simultaneously. Still unsure if I want to make Triple Channel a priority or not at this point.

I'm thinking about increasing the air flow in the case (via a bigger case fan), so the ambient temperate surrounding the CPU is overall cooler. That will really help with overclocking using the stock cooler. Cooling down the ambient temperature in the case seems to have a somewhat direct effect on the cpu temperature, but it's no magic replacement for a better cpu cooler. I've cooled down the max ambient temp in the case by about 3c, and the max cpu temp was lowered by about 1c. So obviously it helps, but it's no replacement for a good cooler.

Also, thinking about getting a Thermalright Ultra-120 eXtreme-1366 CPU Heatsink. It's supposed to be one of the best air coolers on the market, and I'll need it if I want to push the 920 to it's limit.

Updates

2008-12-03: Added info about overclocking the Core i7 920 to 3.4Ghz on "stock" cooler, and added advisory info about overclocking Ram. Also, updated CPU-Z screenshot to show it running at 3.4Ghz.

2008-12-17: Added CINEBENCH Score for Core i7 920 at 3.5Ghz with 175Mhz Base Clock. Also, added links to "validated" CPU-Z dumps for each of the "stock" and 2 highest Core i7 920 overclocks.

Currently rated 4.0 by 4 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Thursday, November 27, 2008 9:33 AM
Permalink | Comments (6) | Post RSSRSS comment feed


ASP.NET AJAX: Create a JavaScript Component with Events

In the spirit of my "Mixing OOP and Event Driving Programming" article I posted a couple days ago; this article discusses how to implement the same thing using the ASP.NET AJAX JavaScript Library. Using inheritence (the ASP.NET AJAX way) it is even easier to implement a little Event Driven Model into your client-side, JavaScript classes/components.

Event Driven Basics

First we'll start by creating a Person class that inherits from the Sys.Component class. Now remember, since we are doing things the ASP.NET AJAX way, we aren't using JavaScript's Prototypal Inheritence.

Person = function() {
    Person.initializeBase(this);
};
Person.prototype = {
    initialize: function() {
        Person.callBaseMethod(this, "initialize");
   },
    dispose: function() {
        Person.callBaseMethod(this, "dispose");
    }
};
Person.registerClass("Person", Sys.Component);

At first glance you may notice that there's a little more plumbing required to inherit from another object using ASP.NET AJAX. This is true, however it does make implementing Events much easier. The magic of inheritence mostly occurs within the call to the "registerClass" method that actually sets up the class/object to inherit from "Sys.Component." It also sets up the "initialize" method to be called when the object is instantiated.

If you have question (and I'm sure you do if you're not familiar with ASP.NET AJAX), please go check out the ASP.NET AJAX Documentation, as further details aren't within the scope of this article.

Now, the hash table that we implemented in the previous article is already implemented for us within the "Sys.Component" class. We can access it using the "private" "get_events" method. The "get_events" method actually returns an instance of the"Sys.EventHandlerList" class that also implements the "getHandler" method for us. This all makes implementing Events much simpler.

First, lets create a "raiseEvent" method, since this isn't created for us. This method will allow us to actually Raise the Events with only a single method call.

Person.prototype = {
    raiseEvent: function(eventName, eventArgs) {
        var handler = this.get_events().getHandler(eventName);
        if (handler) {
            if (!eventArgs) {
                eventArgs = Sys.EventArgs.Empty;
             }
            handler(this, eventArgs);
        }
    }
};

Now lets add the "Name" property (with accessors) to our Person class, and have the "set" accessor Raise the "onchangename" event:

Person.prototype = {
    get_Name: function() {
        return this._name;
    },
    set_Name: function(value) {
        // get old value
        var oldValue = this._name;

        // set new value
        this._name = value;

        // Raise the Event and send the old value as the "EventArgs"
       this.raiseEvent("onchangename", oldValue);
   }
};

Here's an example of using the Person class, and attaching a function to handle the "onchangename" event:

var p = new Person();

p.get_events().addHandler(
        "onchangename",
        function(sender, eventArgs) {
            alert("Old Value: " + eventArgs);
        }
    );

p.set_Name("Charlie");

As you can see in the example event handler that we added above, the function gets passed two parameters (sender and eventArgs). The sender is the Person object that is raising the event, and the eventArgs is this events arguments. So far we are only passing the old Name value as the event arguments, but in the next section of the article we'll see how to create our own EventArgs object that inherits from "Sys.EventArgs" that can contain anything we want to pass to the event handler.

Go Further With Sys.EventArgs

The proper way to raise events in ASP.NET AJAX, is to pass an instance of "Sys.EventArgs" when raising events. This allows you to pass any event arguments to the event handler that you want/need. This also follows suit after the way Events are handled within the .NET Framework.

To do this, we'll first create our own custom EventArgs class that inherits from "Sys.EventArgs", and we'll add "OldName" and "NewName" read-only properties to it (to do this we'll only add 'get' accessors). We'll set the "OldName" and "NewName" properties within the constructor, so we'll make the constructor accept those as well.

PersonEventArgs = function(oldNameValue, newNameValue) {
    this._oldName = oldNameValue;
    this._newName = newNameValue;
};
PersonEventArgs.prototype = {
    get_OldName: function() {
        return this._oldName;
    },
    get_NewName: function() {
        return this._newName;
    }
};
PersonEventArgs.registerClass("PersonEventArgs", Sys.EventArgs);

Now to make use of this new PersonEventArgs class, we just need to change the line of code within the Person class's "Name" properties accessor to the following:

this.raiseEvent("onchangename", new PersonEventArgs(oldValue, this._name));

Now to access the "OldName" and "NewName" properties of the PersonEventArgs when they are passed to the "onchangename" event handler, just call their property accessors. Like the following:

var p = new Person();
p.get_events().addHandler(
    "onchangename",
    function(sender, eventArgs) {
        alert("Old Name: " + eventArgs.get_OldName();
        alert("New Name: " + eventArgs.get_NewName();
   });

Simplify the Adding of Event Handlers

Having to call the "get_events" method, the calling the "addHandler" method and passing it the name of the event can be a little cumbersome. You can create "add_{eventName}" methods that accept one argument (the event handler method) that will add the event handler for you with only one method call, and never needing to pass (and type or misstype) the event name. This is actually how the objects within the ASP.NET AJAX JavaScript library handle adding events. They also implement a "remove_eventName" method that does the same, but removes the event handler passed in.

Person.prototype = {
    add_changeName: function(handler) {
        this.get_events().addHandler("onchangename", handler);
    },
    remove_changeName: function(handler) {
        this.get_events().removeHandler("onchangename", handler);
    }
};

If you compare the below example of adding an event handler for the "onchangename" event, you'll see that it is much simpler to call these methods than the example above.

var p = new Person();
p.add_changeName(function(sender, eventArgs) {
        alert("Old Name: " + eventArgs.get_OldName();
        alert("New Name: " + eventArgs.get_NewName();
   });

Complete Source Code

Heres' the complete code for the Person object created with this article.

First, the example usage code:

var p = new Person();

p.add_changeName(function(sender, eventArgs) {
    alert("Old Name: " + eventArgs.get_OldName());
    //alert("New Name: " + eventArgs.get_NewName());
});

p.set_Name("Charlie");

p.set_Name("Chris");

And, now the full Person and PersonEventArgs code:

Person = function() {
    Person.initializeBase(this);
    this._name = null;
};
Person.prototype = {
    initialize: function() {
        Person.callBaseMethod(this, "initialize");
    },
    dispose: function() {
        Person.callBaseMethod(this, "dispose");
    },

    raiseEvent: function(eventName, eventArgs) {
        var handler = this.get_events().getHandler(eventName);
        if (handler) {
            if (!eventArgs) {
                eventArgs = Sys.EventArgs.Empty;
            }
            handler(this, eventArgs);
        }
    },

    // Property Accessors
    get_Name: function() {
        return this._name;
    },
    set_Name: function(value) {
        // get old value
        var oldValue = this._name;

        // set new value
        this._name = value;

        // Raise the Event and send the old value as the "EventArgs"
        this.raiseEvent("onchangename", new PersonEventArgs(oldValue, this._name));
    },

    add_changeName: function(handler) {
        this.get_events().addHandler("onchangename", handler);
    },
    remove_changeName: function(handler) {
        this.get_events().removeHandler("onchangename", handler);
    }
};
Person.registerClass("Person", Sys.Component);

PersonEventArgs = function(oldNameValue, newNameValue) {
    this._oldName = oldNameValue;
    this._newName = newNameValue;
};
PersonEventArgs.prototype = {
    get_OldName: function() {
        return this._oldName;
    },
    get_NewName: function() {
        return this._newName;
    }
};
PersonEventArgs.registerClass("PersonEventArgs", Sys.EventArgs);

Conclusion

As you can see, it's event easier to add/handle events with your custom classes when you use the ASP.NET AJAX library, rather than implementing it completely yourself. Either way you can use inheritence to greatly simplify things.

Currently rated 2.5 by 2 people

  • Currently 2.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: asp.net | JavaScript
Posted by crpietschmann on Friday, November 07, 2008 9:07 PM
Permalink | Comments (1) | Post RSSRSS comment feed


JavaScript: Mixing OOP and Event Driven Programming

To expand on my previous article on how to create Objects in JavaScript using Prototypal Inheritence, this article will show you how to implement Event Driven Programming with those objects. Implementing Event Driven Programming in JavaScript sounds difficult, but it's actually rather simpel to implement.

To keep with the Prototypal Inheritence theme, we'll create an "EventObject" class that will have the plumbing necessary for implementing Events, and then we'll inherit that class with a simple "Person" class that will have an "onnamechanged" event.

How To Mix OOP and Event Driven Programming in JavaScript

Here's the base EventObject class and Person class with a Name Property (via GetName and SetName property accessors):

EventObject = function() {};
EventObject.prototype = {};

Person = function(name) {
    this._name = name;
};
Person.prototype = new EventObject;
Person.prototype.GetName = function() {
    return this._name;
};
Person.prototype.SetName = function(value) {
    this._name = value;
};

Now, here's some basic example code for using the the Person class:

// Create an instance of the Person Object
var myPerson = new Person("John McCain");

// Get the Name currently set
alert(myPerson.GetName());

// Set the Name Property to a different name
myPerson.SetName("Barack Obama");

// Get the Name currently set
alert(myPerson.GetName());

Now, to the meat of the article.

First we'll create an "internal" Object (that we'll use a hash table) in the EventObject class that will be used to hold references to all the event handlers:

EventObject.prototype = {
    _eventList: {}
};

Next, we'll create "attachEvent" and "detachEvent" methods that will add out event handler methods to the hash for the Event Name specified. Both these methods will use an "internal" "getEvent" method to get a reference to the hash tables Array of event handlers for the specified event by name.

EventObject.prototype = {
    _getEvent: function(eventName, create){
        // Check if Array of Event Handlers has been created
        if (!this._eventList[eventName]){

            // Check if the calling method wants to create the Array
            // if not created. This reduces unneeded memory usage.
            if (!create) {
                return null;
            }

        // Create the Array of Event Handlers
            this._eventList[eventName] = []; // new Array
        }

        // return the Array of Event Handlers already added
        return this._eventList[eventName];
    },
    attachEvent: function(eventName, handler) {
        // Get the Array of Event Handlers
        var evt = this._getEvent(eventName, true);

        // Add the new Event Handler to the Array
        evt.push(handler);
    },
    detachEvent: function(eventName, handler) {
        // Get the Array of Event Handlers
        var evt = this._getEvent(eventName);

        if (!evt) { return; }

        // Helper Method - an Array.indexOf equivalent
        var getArrayIndex = function(array, item){
            for (var i = array.length; i < array.length; i++) {
                if (array[i] && array[i] === item) {
                    return i;
                }
            }
            return -1;
        };

        // Get the Array index of the Event Handler
        var index = getArrayIndex(evt, handler);

        if (index > -1) {
            // Remove Event Handler from Array
            evt.splice(index, 1);
        }
    }
};

Next, we need to add a "raiseEvent" method that allows us to actually Raise the Events. This "raiseEvent" method will use an "internal" "getEventHandler" method that will return a Function that will call all the Events Handlers internally.

EventObject.prototype = {
    raiseEvent: function(eventName, eventArgs) {
        // Get a function that will call all the Event Handlers internally
        var handler = this._getEventHandler(eventName);
        if (handler) {
            // call the handler function
            // Pass in "sender" and "eventArgs" parameters
            handler(this, eventArgs);
        }
    },
    _getEventHandler: function(eventName) {
        // Get Event Handler Array for this Event
        var evt = this._getEvent(eventName, false);
        if (!evt || evt.length === 0) { return null; }

        // Create the Handler method that will use currying to
        // call all the Events Handlers internally
        var h = function(sender, args) {
            for (var i = 0; i < evt.length; i++) {
                evt[i](sender, args);
            }
        };

        // Return this new Handler method
        return h;
    }
};

Now that the "EventObject" class has the Event "plumbing" in place, we are all set to add code to the "Person" class to raise an event. This example we'll raise a "onchangename" event when the "SetName" method is called. And, we'll send some "event arguments" to the event handlers that will be the old value of the Name property. To do this we need to modify the "Person" classes "SetName" method to the following code:

Person.prototype.SetName = function(value) {
    // Get old value
    var oldValue = this._name;

    // Set new value
    this._name = value;

    // Raise "onchangename" event and pass the old
    // value as the event arguments
    this.raiseEvent("onchangename", oldValue);
};

And, now to actually handle the event, we just need to call the "addHandler" method by passing it the name of the event to be handled and a Function that will handle the event.

myPerson.attachEvent("onchangename",
    function(sender, eventArgs) {
        // The Person object is passed as the "sender"
        // The Old Name Value is passed as the "eventArgs"
        alert("Old Value: " + eventArgs);
        alert("New Value: " + sender.GetName());
    }
);

Complete Source Code Listing

EventObject = function() {};
EventObject.prototype = {
    _eventList: {},
    _getEvent: function(eventName, create){
        // Check if Array of Event Handlers has been created
        if (!this._eventList[eventName]){

            // Check if the calling method wants to create the Array
            // if not created. This reduces unneeded memory usage.
            if (!create) {
                return null;
            }

        // Create the Array of Event Handlers
            this._eventList[eventName] = []; // new Array
        }

        // return the Array of Event Handlers already added
        return this._eventList[eventName];
    },
    attachEvent: function(eventName, handler) {
        // Get the Array of Event Handlers
        var evt = this._getEvent(eventName, true);

        // Add the new Event Handler to the Array
        evt.push(handler);
    },
    detachEvent: function(eventName, handler) {
        // Get the Array of Event Handlers
        var evt = this._getEvent(eventName);

        if (!evt) { return; }

        // Helper Method - an Array.indexOf equivalent
        var getArrayIndex = function(array, item){
            for (var i = array.length; i < array.length; i++) {
                if (array[i] && array[i] === item) {
                    return i;
                }
            }
            return -1;
        };

        // Get the Array index of the Event Handler
        var index = getArrayIndex(evt, handler);

        if (index > -1) {
            // Remove Event Handler from Array
            evt.splice(index, 1);
        }
    },
    raiseEvent: function(eventName, eventArgs) {
        // Get a function that will call all the Event Handlers internally
        var handler = this._getEventHandler(eventName);
        if (handler) {
            // call the handler function
            // Pass in "sender" and "eventArgs" parameters
            handler(this, eventArgs);
        }
    },
    _getEventHandler: function(eventName) {
        // Get Event Handler Array for this Event
        var evt = this._getEvent(eventName, false);
        if (!evt || evt.length === 0) { return null; }

        // Create the Handler method that will use currying to
        // call all the Events Handlers internally
        var h = function(sender, args) {
            for (var i = 0; i < evt.length; i++) {
                evt[i](sender, args);
            }
        };

        // Return this new Handler method
        return h;
    }
};



Person = function(name) {
    this._name = name;
    this._eventList = {};
};
Person.prototype = new EventObject;
Person.prototype.GetName = function() {
    return this._name;
};
Person.prototype.SetName = function(value) {
    // Get old value
    var oldValue = this._name;

    // Set new value
    this._name = value;

    // Raise "onchangename" event and pass the old
    // value as the event arguments
    this.raiseEvent("onchangename", oldValue);
};




// Create an instance of the Person Object
var myPerson = new Person("John McCain");

// Get the Name currently set
alert(myPerson.GetName());


myPerson.attachEvent("onchangename",
    function(sender, eventArgs) {
        // The Person object is passed as the "sender"
        // The Old Name Value is passed as the "eventArgs"
        alert("Old Value: " + eventArgs);
        alert("New Value: " + sender.GetName());
    }
);

// Set the Name Property to a different name
myPerson.SetName("Barack Obama");


// Get the Name currently set
alert(myPerson.GetName());

Conclusion

As you can see, it's a little involved to be able to implement Event Driven Programming in you JavaScript Object, but it's really not that complicated. Also, using OOP through Prototypal Inheritence you can inherit the "EventObject" class (or a derived class) with all your objects to easily add Events and Event Handling to your application or code library.

If you have any questions, please ask. And, if you have any requests for future JavaScript articles, please let me know.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: JavaScript
Posted by crpietschmann on Tuesday, November 04, 2008 10:53 PM
Permalink | Comments (0) | Post RSSRSS comment feed


Implementing Namespaces in Ruby using Nested Modules

Recently, I finally got around to starting to learn Ruby. I am finding it to be rather pleasant to program in. Now, one thing that I am used to using with an Object Oriented language (especially with my .NET background) are Namespaces. The only problem is that you can't just declare a namespace in Ruby using a "namespace" keyword. However, it's not difficult to implement Namespaces in Ruby, all you need to do is nest some modules.

To demonstrate this, I'll show you how to create the familiar (for .NET developers) System.Windows.Forms namespace with the MessageBox.Show method:

module System
  module Windows
    module Forms
      module MessageBox
        def MessageBox.Show(title, message)
          api = Win32API.new("user32","MessageBox",["L","P","P","L"],"I")
          api.call(0, message, title, 0)
        end
      end
    end
  end
end

Now to use the namespace you can use one of the following methods:

System::Windows::Forms::MessageBox.Show("Some Title", "This is a test message.")

Or by including the "namespace":

include System::Windows::Forms

MessageBox.Show("Some Title", "This is another test message.")

As you can see it's rather simple to create ".NET"-like namespaces in Ruby.

Now, I know this technique is basically allowing me to write .NET code in Ruby, but that was pretty much the point of figuring this out. Now, back to learning how to write Ruby code in Ruby.

 

Oh, yeah now only if the syntax highlighter in BlogEngine.NET supported Ruby....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: Ruby
Posted by crpietschmann on Sunday, November 02, 2008 6:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2009 Chris Pietschmann