Posts Tagged With: js

Finding the Factorial using Recursion

Tagged with: , , , ,

Finding the Factorial using Recursion in javascript.


function factorial(x) {
	if(x <= 1) return 1;
	return x*factorial(x-1);
}
factorial(5);
No Comments »

Chainable interface in JavaScript

Tagged with: , , , , , ,

Creating Chainable interfaces in javascript…


(function() {
	function _init() {
		return this;
	}

	_init.prototype = {
		"myFunction": function() {
			return this;
		}

		// Put all the functions here - make sure all 'return this;'
	}

	chainer = function() {
		return new _init();
	}
})();

Roll out your own JavaScript Interfaces

[tags][/tags]

No Comments »

Execute JavaScript files using Rhino

Tagged with: , , , ,

The command to execute a javascript file using rhino.


java -jar /path/to/custom_rhino.jar JS_File.js

Get Custom Rhino(From Dojo Library)

No Comments »

Find Element’s Position using JavaScript

Tagged with: , , , , , , ,

Find the position of an element using javascript


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

Original Article

7 Comments »