This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call functionality | |
var bar = 80; | |
function foo(){ | |
console.log(this.bar); | |
} | |
var obj = {'bar' : 10}; | |
var obj2 = {'bar' : 20}; | |
foo.call(obj2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mySingleton = (function () { | |
// Instance stores a reference to the Singleton | |
var instance; | |
function init() { | |
// Singleton | |
// Private methods and variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shape(){ | |
} | |
shape.prototype.sayhello = function(){} | |
function newShape(){ | |
} | |
// copy prototype | |
newShape.prototype = shape.prototype; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extend(Child, Parent) { | |
var F = function () {}; | |
F.prototype = Parent.prototype; | |
Child.prototype = new F(); | |
Child.prototype.constructor = Child; | |
Child.uber = Parent.prototype; | |
} | |
// Using this function (or your own custom version of it) helps you keep your code clean with regard to the repetitive inheritance-related tasks. This way you can inherit by simply using: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var person = { | |
firstname: "Albert", | |
lastname: "Einstein", | |
get fullname() { | |
return this.firstname +" "+this.lastname; | |
}, | |
set fullname(_name){ | |
var words = _name.toString().split(' '); | |
this.firstname = words[0]; | |
this.lastname = words[1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
, path = 'my_file.txt' | |
function getFile(path, callback) { | |
try { | |
fs.readFile(path, function(err, data) { | |
if(err) throw err | |
var wrapperMessage = {coolStuff: true, data: data} | |
callback(null, wrapperMessage) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findLikesForPostsByUsername(username, callback) { | |
findUserByUsername(username, function(err, user) { | |
if(err) return callback(err) | |
findPostsByUser(user, function(err, posts) { | |
if(err) return callback(err) | |
findLikesByPosts(posts, function(err, likes) { | |
if(err) return callback(err) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('special-http') | |
function getData(endpoint) { | |
var promise = new Promise(function(resolver, rejector) { | |
http.get(endpoint).then(function(data) { | |
resolver(data) | |
}, function(err) { | |
rejector(err) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
module.exports = { | |
entry: { | |
'vendor': './src/vendor.ts', | |
'polyfills': './src/polyfills.ts', | |
'app': './src/main.ts' | |
}, | |
resolve: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormsModule } from '@angular/forms'; | |
import LoaderComponent from './loader/loader-component'; | |
import { NgModule } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { AppComponent } from './app.component'; | |
import HeaderComponent from './header/app-header'; | |
import FooterComponent from './footer/app-footer'; | |
import MainComponent from './main/main-result'; | |
import {LoaderService} from './loader/loader-service'; | |
import {HttpClient} from './http.service'; |