Skip to content

Instantly share code, notes, and snippets.

Avatar
🐶
Working on Web stuff !

Adarsh Konchady akonchady

🐶
Working on Web stuff !
View GitHub Profile
View inheritance2.js
function Animal() {
this.offspring = [];
}
function Dog() {
Animal.call(this); // Use Animal.call(this, args) if any arguments
// exist. Else, use 'apply'
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
var d1 = new Dog();
View inheritance1.js
function Animal() {
this.offspring = [];
}
function Dog() {
}
Dog.prototype = new Animal();
Dog.prototype.constructor = Dog;
var d1 = new Dog();
var d2 = new Dog();
var pup = new Dog();
View isInViewport.js
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
if (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
) {
return true;