Skip to content

Instantly share code, notes, and snippets.

View tkssharma's full-sized avatar
🎯
only JS

codewithtkssharma tkssharma

🎯
only JS
View GitHub Profile
// call functionality
var bar = 80;
function foo(){
console.log(this.bar);
}
var obj = {'bar' : 10};
var obj2 = {'bar' : 20};
foo.call(obj2);
var mySingleton = (function () {
// Instance stores a reference to the Singleton
var instance;
function init() {
// Singleton
// Private methods and variables
function shape(){
}
shape.prototype.sayhello = function(){}
function newShape(){
}
// copy prototype
newShape.prototype = shape.prototype;
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:
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];
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)
})
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)
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)
})
})
var webpack = require('webpack');
module.exports = {
entry: {
'vendor': './src/vendor.ts',
'polyfills': './src/polyfills.ts',
'app': './src/main.ts'
},
resolve: {
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';