Skip to content

Instantly share code, notes, and snippets.

View ivan-ha's full-sized avatar
๐Ÿ‘จโ€๐Ÿ’ป
cannot read property 'status' of undefined ๐Ÿ˜„

Ivan Ha ivan-ha

๐Ÿ‘จโ€๐Ÿ’ป
cannot read property 'status' of undefined ๐Ÿ˜„
View GitHub Profile
;(function(global, $) {
// 'new' an object
var Greetr = function(firstName, lastName, language) {
return new Greetr.init(firstName, lastName, language);
}
// hidden within the scope of the IIFE and never directly accessible
var supportedLangs = ['en', 'es'];
@ivan-ha
ivan-ha / functional-programming.js
Created March 2, 2017 14:04
Functional programming in js
function mapForEach(array, fn) {
var tmpArr = [];
for (var i = 0; i < array.length; i++) {
tmpArr.push(
fn(arr[i])
);
}
return tmpArr;
@ivan-ha
ivan-ha / call-apply-bind.js
Created March 1, 2017 15:31
Usage of call(), apply(), bind() in js
var person = {
firstname: 'John',
lastname: 'Doe',
getFullName: function() {
return this.firstname + ' ' + this.lastname;
}
}
var logName = function(arg1, arg2) {
console.log('Logged: ' + this.getFullName());
@ivan-ha
ivan-ha / bookmark-url.md
Last active October 12, 2017 01:48
My bookmark url list. Updating from time to time
@ivan-ha
ivan-ha / function-factory.js
Created February 23, 2017 13:05
Function factory using closure in js
function makeGreeting(language) {
return function (name) {
if (language == 'en') {
console.log('Hello ' + name);
}
else if (language == 'es') {
console.log('Hola ' + name);
}
};
}
@ivan-ha
ivan-ha / closure-explanation.js
Last active February 22, 2017 16:55
js closure explanation
// same execution context, all pointing to same memory location
// so by the time running console.log(i), i will be its final value (i.e. 3)
function buildFunctions() {
var arr = [];
for (var i = 0; i < 3; i++) {
arr.push(
function () {
console.log(i);
}
);