Skip to content

Instantly share code, notes, and snippets.

View AjayPoshak's full-sized avatar

Ajay Poshak AjayPoshak

View GitHub Profile
@AjayPoshak
AjayPoshak / prototype.js
Last active January 20, 2018 16:40
Initialization of Prototype
function Notification() {
this.notifs = ['A', 'B', 'C']
this.readNotifs = ['B']
this.isPublic = false
}
@AjayPoshak
AjayPoshak / prototype-methods.js
Last active March 25, 2018 13:09
Adding methods to prototypes
var Notification = function () {
this.notifs = ['A', 'B', 'C']
this.readNotifs = ['B']
this.isPublic = false
}
Notification.prototype = {
markNotifsRead: function() {
//Mark notification read
}
@AjayPoshak
AjayPoshak / prototype-inst.js
Created January 20, 2018 15:52
instantiate prototypes
var eventsNotifs = new Notification();
console.log(eventsNotifs.notifs); // Output: A, B, C
eventsNotifs.markAllNotifsRead(); // Mark all notification as read
@AjayPoshak
AjayPoshak / webpack.config.js
Last active July 14, 2018 15:02
Initial webpack config
const path = require('path'),
AssetsPlugin = require('assets-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'inline-source-map',
entry: './client/index.js',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'build/client'),
...
devtool: '', // Removed dev-tools mapping
entry: './client/index.js',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'build/client'),
publicPath: 'build/client'
},
...
...
plugins: [
new BrotliPlugin({
asset: '[path].br[query]',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
})
],
...
...
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
const path = require('path'),
webpack = require('webpack'),
AssetsPlugin = require('assets-webpack-plugin'),
BrotliPlugin = require('brotli-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production';
/**
@AjayPoshak
AjayPoshak / newFunction.js
Created July 1, 2019 14:05
Function to implement new keyword
function newFunction(funcName, args) {
// Copy the function prototype to object
let obj = Object.create(funcName.prototype)
// Call constructor function with supplied arguments, and assign this to newly created object
funcName.call(obj, args)
// return newly created object
return obj
}
function MinHeap() {
this.arr = new Array()
}
MinHeap.prototype.push = function push(data, weight) {
this.arr.push({ data, weight })
if(this.arr.length <= 1) return
let current = this.arr.length - 1
let parent = Math.floor(current/2)