chris clarke
software development that works…or something
How many developers does it take to change a light bulb?
September 30, 2007 on 7:31 pm | In Uncategorized | No Comments
Well, you gotta re-deploy the lightbulb application, should take a couple of minutes right? First up you have to upgrade CrappyAppServer because the boss said so. OK, so you install the new version of CrappyAppServer, but there’s a problem, you’ve run out of disk quota. But you can’t increase the disk quota yourself, you have to contact some other guy in some other department. You send the guy an email. Nothing. You escalate it to his manager. You get an email, apparently you have to fill out a form to get the disk quota increased. You ask “Do I really have to fill out the form? I only need a few more gigs and you only have to run one command.”. Yes, apparently without the form and appropriate signatures it can’t be ‘processed’. Now the form requires you to know the physical location of the box but of course you don’t know so you have to contact some other guy in some other department and it goes on and on and on ….
Private, Public and Static in JavaScript
September 22, 2007 on 4:30 pm | In JavaScript | No CommentsJavaScript doesn’t have keywords for making things private, public or static like other languages but it is possible - unfortunately like most things in JavaScript it’s possible in several different ways!
Public and private access in JavaScript
To declare a method public in JavaScript you can assign it to the prototype:
// The class
Monkey = function () {};
// The public method getBananas
Monkey.prototype.getBananas = function() { ... };
..or you can also assign it to this in the constructor:
Monkey = function () {
this.getBananas = function () { ... };
};
To make things private you can take different approaches aswell. You can just define them to a var in the constructor:
Monkey = function () {
var privateMethod = function () { ... };
};
…or you can use the approach Carlos Villela suggests and define your public and private methods in different objects inside the constructor and return the public object:
Monkey = function() {
var private = {
privateMethod : function () { ... }
};
var public = {
getBananas : function () { ... }
};
return public;
}();
Static members in JavaScript
Static members are easy, you just define them directly on the class:
Monkey.MAX_BANANAS = 120;
Monkey.swingFromTree = function () { ... }
Powered by Cheese.
RSS Entries Feed.
RSS Comments Feed
^Top^