Skip to content

Instantly share code, notes, and snippets.

View abrjagad's full-sized avatar

Abraham Jagadeesh abrjagad

View GitHub Profile
@abrjagad
abrjagad / Javascript Object.js
Last active August 29, 2015 14:11
Javascript Object
//http://javascriptissexy.com/javascript-objects-in-detail/
//everything in javascript is objects.
//except number, strings & boolean
//objects are key/value pairs
//anything ends with () is a function
//in that way; new Object() is also a function
//and it has methods like create()
// and hasOwnProperty()
@abrjagad
abrjagad / Date.js
Last active August 29, 2015 14:05
Jquery Date
var d, h, m, s,
ms = $newDate - $currentDate;
s = Math.floor(ms / 1000);
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
$(document).keydown(function (e) {
if (e.keyCode == 27)
{ $(".box_tube,.over_wrapper").fadeOut(500); }
});
function upTo(element, myclassName) {
do {
element = element.parentNode;
if (element.className.indexOf(myclassName) > -1) {
return element;
}
} while (element);
return null;
}
upTo(this, "level-dt");
@abrjagad
abrjagad / example for call and apply
Created April 27, 2014 13:17
example for call and apply
var log_this_and_message = function (message) {
console.log(message+this.name);
};
var thing = {
name: 'Big Hairy Thing'
};
log_this_and_message.call(thing, 'Hello!');
@abrjagad
abrjagad / allow only one check box checked in group
Created March 18, 2014 08:20
allow only one check box checked in group
$(".accord_table").on("change",'.currentTable :checkbox',function(event){
var group = $(this).closest(".currentTable").find(":checkbox");
group.not($(this)).removeProp("checked");
})
@abrjagad
abrjagad / css browser hacks
Created March 16, 2014 05:12
css browser hacks
@media screen and (-webkit-min-device-pixel-ratio:0) { // for chrome
}
//Invocation as a function
//this refers to window
function creep() {
return this;
}
console.log(creep() === window, "Creeping in the window");
//Invocation as a constructor
//Ninja is a Constructor
//should start with Capital letter
//creates a emply object{}
function Ninja() {
this.skulk = function () {
return this;
@abrjagad
abrjagad / Invocation with the apply() and call() methods
Created February 13, 2014 08:54
Explaining Call and Apply; basically call and apply Invoke a Function with the given set of arguments
//Invocation with the apply() and call() methods
// create a plain function
function juggle() {
var result = 0;
for (var n = 0; n < arguments.length; n++) {
result += arguments[n];
}
//this.result = result;
console.log(result)