Dec 20, 2018

RePost - Chrome inspector - network - inspect traffic - Ajax - MISC

chrome://net-internals/#events

https://stackoverflow.com/questions/17208268/how-to-find-out-which-javascript-causes-a-jquery-ajax-request/17210212


Dec 17, 2018

Javascript OOP - Example of inheritance with closure (module pattern)

//This is just wrapper function! Not a constructor! It's sole purpose is to provide
//closure for hiding private members. Module?
function Vehicle(type, registration){
//Private members
var defaultType = 'car';
var calcRegistration = function (registration){
return registration ? 'REG-'+registration : 'REG-UNKNOWN';
}
//(Public) Constructor
function Vehicle(type, registration){
this.Type = type || defaultType;
this.Registration = calcRegistration(registration);
}
//Public method
Vehicle.prototype.DumpData = function(){
console.log(this.Type,' ',this.Registration);
}
//object instantiation using constructor and provided params
return new Vehicle(type, registration);
}
function Bus(type, registration, passengers){
function Bus(type, registration, passengers){
//Call base constructor with params
Vehicle.call(this,type,registration);
this.Passengers = passengers;
this.Driver = "";
}
//Inherit methods from prototype of Parent
Bus.prototype = new Vehicle(type, registration, passengers);
//Revert to child constructor
Bus.prototype.constructor = Bus;
//Create new method on child prototype
//Note! Parent method DumpData is inheried/exists on child->prototype->prototoype
Bus.prototype.AssignDriver = function(){
if (this.Passengers>30)
{
this.Driver= "Jack";
}
else
{
this.Driver = "Jenny";
}
}
return new Bus(type, registration, passengers);
}

//new is not needed since Bus function is used to create instance.
var cityBus = new Bus('bus','ZZX23-1',10);
cityBus.AssignDriver();
console.log(cityBus);
var fordTransit = Vehicle('van','');
console.log(fordTransit);
fordTransit.DumpData();