Skip to content

Instantly share code, notes, and snippets.

//class emulation adding inheritance
var Class = function(parent){
var klass = function(){
this.init.apply(this, arguments);
};
// Change klass' prototype
//If a parent is passed to the Class constructor
//we make sure any subclasses share the same prototype.
//creating a temporary anonymous function prevents instances
@zgangx
zgangx / jsbin.herifof.js
Last active September 16, 2020 21:21
Function invocation with apply
//this context change by using apply
var proxy = function(func, thisObject){
return(function(){
return func.apply(thisObject, arguments);
});
};
var clicky = {
name: 'my name is proxy',
wasClicked: function(){
console.log(this.name)
@zgangx
zgangx / jsbin.catipoz.js
Last active September 16, 2020 18:16
Javascript Class inheritance using prototype
//Javascript Class inheritance using prototype
//To subclass a class and inherit its properties
//you need to first define a constructor function.
//Then, you need to assign a new instance of the parent class
//as the prototype for your constructor function
var Animal = function(){};
Animal.prototype.breath = function(){
console.log('breath');
@zgangx
zgangx / jsbin.jesemabamo.js
Last active September 16, 2020 18:03
javascript class emulation
//if you call contructor function without new prefix.
//function return undefined and create a global variable name
//window.name = 'bob'
// new prefix is creae a new empty context and switches from global
// to current instance.
//By default, if you don’t return anything from a constructor function
//this—the current context—will be returned.
//Otherwise, you can return any nonprimitive type.
//For example, we could return a function that would set up a new class
$ cd ~
$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer
then you can run
$ sudo composer install