This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |