Monday, October 29th, 2007 10:46 PM
Prints all the arguments of the function. This function uses console.log if firebug is available - else, uses alert.
function p() {
for(var i=0; i<<arguments.length; i++) {
if(window.console) console.log(arguments[i]);
else alert(arguments[i]);
}
}
No Comments »
Sunday, October 28th, 2007 10:44 PM
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 »
Tuesday, October 16th, 2007 11:51 PM
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 »
Saturday, October 13th, 2007 11:01 PM
Installing Rhino(Javascript interpreter created in java) on Fedora 7
sudo yum install rhino-manual rhino-demo rhino
No Comments »
Tuesday, August 28th, 2007 10:40 PM
Function x executions in the scope of object y.
var Car = function() { this.name = 'car'; }
var Truck = function() { this.name = 'truck'; }
var func = function() { alert(this.name); }
var c = new Car();
var t = new Truck();
func.apply(c);
func.apply(t);
Original Article
[tags]javascript,apply,call,binding[/tags]
No Comments »
Saturday, June 23rd, 2007 02:48 PM
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
4 Comments »
Tuesday, March 27th, 2007 12:07 AM
Javascript code for finding the fourth sunday in any given month.
function findFourthSunday(year,month) {
var fourth_sunday = 0;
var sunday_count = 0;
//There is a really cool solution for this
//forth_sunday = 29 - first_day_of_month
//But the problem is if the first of month is a sunday(first_day_of_month == 0), then there will be a bug. Found the bug in April 2007
for(var i=1;i<31;i++) {
var a_day = new Date(year,month,i);
if(a_day.getDay() == 0) sunday_count++;//'0' means sunday - 1 for monday, etc.
if(sunday_count == 4) {
fourth_sunday = i;
break;
}
}
return fourth_sunday;
}
function init() {
var month_names = new Array("January","February","March","April","May","June","July","Augest","September","October","November","December");
var first_day = ""
var today = new Date();
var year = today.getYear();
year = (year > 2000) ? year : year + 1900;
var month = today.getMonth();
var fourth_sunday = findFourthSunday(year,month);
if(today.getDate() > fourth_sunday) {
month ++;
fourth_sunday = findFourthSunday(year,month);
} else if(today.getDate() == fourth_sunday) {
fourth_sunday = "Today - " + fourth_sunday;
}
var date = fourth_sunday + " " + month_names[month] + ", " + year;
alert(date);
}
window.onload=init;
[tags]javascript,fourth,sunday,calender,month,date,day,code[/tags]
No Comments »
Wednesday, March 14th, 2007 07:44 AM
For best results use a framework - like jx
http = window.XMLHttpRequest ? new window.XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("MSXML2.XMLHTTP"): null);
Original Article
[tags]javascript,ajax,code,xhr[/tags]
1 Comment »
Tuesday, March 6th, 2007 08:44 AM
Find whether the given variable is an object,or is an Array?
function isArray(testObject) {
return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}
Original Page
[tags]javascript,object,array,type[/tags]
No Comments »