Page 168 of 171

Using namespaces (modules) in Javascript

Recently I've been developing my own GUI engine in Javascript.

Nothing fancy, however it is quite big so I've decided to use namespaces (modules).

After reading some tutorials I've found Gravatar comment here.

I've really liked his method so I've decided to use it in my own projects. If you want to use namespaces, place this piece of code before any other JS stuff:

String.prototype.namespace = function(source) {
    Object.extend(this.split('.').inject(window, function(parent, child) {
        return (parent[child] = parent[child] || { });
    }), source || { });
}

Now You can use namespaces like this:

'Space.Subspace.Methods'.namespace({
    method: function(){
        alert('h hello world!');
    },
    method2: function(){
        alert('bye bye worlds!')
    }
});

After defining module, using its method is quite easy:

    Space.Subspace.Methods.method();
    Space.Subspace.Methods.method2();

There's more! Creating classes inside modules. First our base class (Class.create is a part of Prototype library):

var Parent = Class.create({
    class_method: function(){
        alert('im here!')
    }
});

Inheritance and namespace:

'Space.Subspace.Klasses'.namespace({
    SuperClass: Class.create(Parent, {})
});

I nie pozostaje nam nic innego jak utworzyć instancję klasy i sprawdzić czy działa:

    a = new Space.Subspace.Klasses.SuperClass();
    a.class_method();

How to clean a laptop keyboard

Recently, I've decided to clean my laptop keyboard and make a small tutorial for those interested in this topic.

First of all, check on ebay whether you can buy extra keys or not. If not - don't clean it like this. You don't want to break anything right? I've never broke any of keys but better be cautious.

Let's start'. I'll be cleaning by Toshiba A200-1H, however most of low-profile keyboards have same working mechanism.

Some important rules:

  • Do not be brutal - it is delicate stuff
  • No water or any other fluids!
  • No electricity
  • If you're cleaning notebook - remove the battery
  • Disconnect all external devices
  • Clean up the workplace (probably some kind of desktop ;) )
  • Prepare the camera to be able to take a picture (it's not so easy to remember right keys order)
  • Prepare small flat bladed screwdriver and some cotton buds

All steps are illustrated below.

First of all - take a picture of your keyboard. It will help you after cleaning. You would like to attach them in the same order, right? :)

Removing the keys is the hardest part. Each key has two "teeth" which bind them with the rest of the keyboard. They are (in most cases) located at the top of each key. It shouldn’t be hard to locate them. Slightly undermine top part of the key. You should hear characteristic "click". After top part "jumped" out - do the same with bottom key part.

Try not to break key mechanism because you will be forced to use ebay ;)

Repeat procedure for all the keys. Bigger keys (space, backspace and enter) have metal "frame" that holds them. However, this frame is not a problem.

When all the keys are out, you should place them for a few hours in water with a little bit of  dish-washing liquid. It will dissolve dirt and make them look like new.

Meanwhile we can clean up "naked" keyboard with vacuum cleaner. Rest remove using cotton buds.

After cleaning keys - take them out of water, put them on a tea-towel and let them get dry.

Assembling keys is really easy. First attach bottom part of key and press it until you hear "click". After that, do the same thing with upper key part.

You clean it up at your own risk!

 

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑