Skip to content

Instantly share code, notes, and snippets.

View optimistanoop's full-sized avatar
💭
<tod-fod-code>

Anoop Kumar optimistanoop

💭
<tod-fod-code>
View GitHub Profile
@optimistanoop
optimistanoop / app.js
Created January 14, 2017 07:30
Special behaviour of Js functions, we can attach properties to the function object
var car = function(){
console.log('car');
}
car.name = "baleno";
car.obj = {a:1};
car(); // car
console.log(car); // function(){console.log('car')}, this is an object actually
console.log(car.name) // "baleno"
@optimistanoop
optimistanoop / app.js
Last active January 14, 2017 18:43
Closures in Js
// A closure is just any function that some how remains available after the outer scope have returned.
//A closure is a function having access to the parent scope, even after the parent function has closed.
var fns = [];
(function(){
var available = "available";
fns.push(function(){console.log(Random()+available)});
fns[0](); // 1available
@optimistanoop
optimistanoop / app.js
Created January 15, 2017 10:12
Javascript call() & apply() vs bind()
var person = {
name: "James Smith",
hello: function(thing) {
console.log(this.name + " says hello " + thing);
}
}
// call is used to call a function with desired this and comma seprated function argument
var context = {name:"Anoop"};
person.hello.call(context, "world"); // Anoop says hello world
@optimistanoop
optimistanoop / app.js
Last active January 15, 2017 10:47
Object decorator pattern in Js
// Object decorator pattern is a pattern in which we have a function which rely on params passed ,
// and adds different properties to the object.
var fourWheeler = function(obj, location){
obj.location = location;
obj.move = function(){
// above obj.location will remain accessable for move fnction due closure scope in excusion contex.
obj.location++;
console.log(obj.location);
}
@optimistanoop
optimistanoop / app.js
Last active January 15, 2017 11:59
functional classes in Js (functional pattern)
//functional classes creates and return object by their own , they don't rely on params.
var FourWheeler = function(location){
var obj = {};
obj.location = location;
obj.move = function(){
// above obj.location will remain accessable for move fnction due closure scope in excusion contex.
obj.location++;
console.log(obj.location);
}
@optimistanoop
optimistanoop / app.js
Created January 15, 2017 11:26
prototypical classes in Js
// Prototypical classes delegates any lookup to prototype object
var FourWheeler = function(location){
var obj = Object.create(FourWheeler.prototype); // this line will be duplicated everytime we create class
// hence js has special features for this line in pseudoclassical pattern
obj.location = location;
return obj; // this line will be duplicated everytime we create class
// hence js has some special features for this line in pseudoclassical pattern
};
@optimistanoop
optimistanoop / app.js
Created January 15, 2017 11:36
Pseudoclassical pattern in Js
// In Pseudoclassical pattern, we need not to write prototypical property by Object.create
// as well as we need not to return any object from constructor function. Both things is done by Js engin.
// new keyword is mendetory in this pattern for instantiation.
// This pattern is most optimized pattern in OOP Js.
var FourWheeler = function(location){
this.location = location;
};
FourWheeler.prototype.move = function(){
this.location++;
@optimistanoop
optimistanoop / app.js
Created January 15, 2017 11:52
Sub Classes in Js
// Sub classes in Js are simpler concepts
// A class can be made sub class of any class if that is called from any parent class
// and the returned value of the sub class is attached to the instance of the parent class.
var FourWheeler = function(location){
var obj = {};
obj.location = location;
obj.move = function(){
// above obj.location will remain accessable for move fnction due closure scope in excusion contex.
@optimistanoop
optimistanoop / app.md
Last active May 21, 2017 17:21
Pseudoclassical subclasses in Js
  • Pseudoclassical subclasses in Js are most optimised subclasses in Js

  • optimised as the prototypical methods are inherited by the new instances hence we optimised it by not creating a method in cunstructor everytime we call a custructor for new instance.

  • prototypical methods are not created everytime for every new instance or custructor call

  • prototypical methods are inherited for every new instance or custructor call.

  • as a nature of prototypes or can say Object.create(FourWheeler.prototype) every change in prototype obj is reflected to all the other instances created.

    var FourWheeler = function(location){
    

this.location = location;

@optimistanoop
optimistanoop / app.md
Last active May 21, 2017 17:18
Js topics
  • XHRF
  • csrf
  • CORS
  • scurity issues in js and what we do for it
  • http , https, http 2 advantages and problems
  • http methods (verbs) get , post, put , delete, head , options
  • architechure of transport layer and network layer, - ethernet -> ip -> tcp -> http
  • token based auth
  • currying
  • full fledge use cases of bind