Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 81 Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 82 Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 81 Warning: count(): Parameter must be an array or an object that implements Countable in /customers/d/f/8/sveitech.dk/httpd.www/wp-content/plugins/css-javascript-toolbox/framework/events/subjects/hook.subject.php on line 82 Javascript | Sveitech

Javascript

Everything is an Object

Everything in Javascript is an object, even functions. This allows us to create som peculiar functionality. Take JQuery for example, where the jquery object $ is used both as a function and an object. The code below illustrates the most basic custom implementation of a module similar to jquery.

var $ = (function() {
    var module = function(identifier) {
	console.log("Identifier is : " + identifier);
    };

    module.add = function(a, b) {
	return a + b;
    };

    return module;
})();

$('foo');

console.log($.add(10, 20));

There is nothing special about the $ sign. It’s a perfectly valid character to use in variable names.

Sveistrup Technologies