Skip to content

Instantly share code, notes, and snippets.

View appkr's full-sized avatar
🎯
Focusing

appkr appkr

🎯
Focusing
View GitHub Profile
@appkr
appkr / jsbin.gepage.js
Last active August 29, 2015 14:14
JavaScript This Keyword// source http://jsbin.com/gepage
// "this" keyword
var makeRequest = function(url, callback) {
var data = 10; // Ajax
callback(data);
};
var obj = {
someValue : 20,
loadData: function(data) {
var sum = this.someValue + data;
@appkr
appkr / jsbin.muraqe.js
Last active August 29, 2015 14:14
JavaScript Data & Accessor// source http://jsbin.com/muraqe
var createPerson = function(firstName, lastName) {
var person = {};
Object.defineProperties(person, {
firstName : {
value : firstName,
enumerable : true
},
lastName : {
value : lastName,
@appkr
appkr / jsbin.mawohi.js
Last active August 29, 2015 14:14
JavaScript Parachutic Inheritance// source http://jsbin.com/mawohi
var createPerson = function(firstName, lastName) {
var person = {
firstName : firstName,
lastName : lastName,
sayHello : function () {
return "Hi there?";
}
};
Object.defineProperty(person, "fullName", {
@appkr
appkr / jsbin.hiteva.js
Last active August 29, 2015 14:14
JavaScript Prototypal Inheritance// source http://jsbin.com/hiteva
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
Object.defineProperties(Person.prototype, {
sayHi : {
value : function () {
return "Hi there";
},
@appkr
appkr / jsbin.xuvoga.js
Last active August 29, 2015 14:14
JavaScript Constructor// source http://jsbin.com/xuvoga
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
// every object from Person has below properties.
Object.defineProperties(Person.prototype, {
sayHi : {
value : function () {
return "Hi there ?";
@appkr
appkr / jsbin.kipame.js
Last active August 29, 2015 14:14
JavaScript Event Target// source http://jsbin.com/kipame
var EventTarget = function() {
Object.defineProperty(this, "__listeners", {
value: {}
});
};
Object.defineProperties(EventTarget.prototype, {
addListener: {
value: function(type, listener) {
if (typeof this.__listeners[type] === "undefined") {
@appkr
appkr / jsbin.noveqe.css
Last active August 29, 2015 14:14
JavaScript Toolbar Example - Add Event// source http://jsbin.com/noveqe
.toolbar {
background-color: #c6c6c6;
/*height: 50px;*/
padding: 5px;
}
.toolbar-item {
display: inline-block;
height: 50px;
width: 50px;
@appkr
appkr / jsbin.qofali.js
Last active August 29, 2015 14:14
JavaScript Protytypal Inheritance 2 from CodeSchool// source http://jsbin.com/qofali
var Shoe = function(shoeSize, shoeColor, forGender, constructStyle) {
this.size = shoeSize;
this.color = shoeColor;
this.gender = forGender;
this.construction = constructStyle;
};
Shoe.prototype = {
putOn: function() {
alert("Your " + this.construction + "'s " + "on, dude!");
@appkr
appkr / jsbin.posusi.js
Last active August 29, 2015 14:14
JavaScript Method Overriding// source http://jsbin.com/posusi
Number.prototype.numberFormat = function (){
return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
Object.prototype.getName = function() {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
@appkr
appkr / jsbin.lapaca.js
Last active August 29, 2015 14:14
JavaScript Ticketing Example// source http://jsbin.com/lapaca
var parkRides = [
["Birch Bumper", 40],
["Pines Plunge", 55],
["Cedar Coaster", 20],
["Ferries Whell of Fires", 90]
];
var fastPassQueue = [
"Cedar Coaster",
"Pines Plunge",