Last active
July 5, 2016 21:19
-
-
Save omarkdev/dc6e58d1a71f40c1f6a4ec0ec74a8823 to your computer and use it in GitHub Desktop.
Prototype JS para PHP Developers
This file contains hidden or 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
//Instanciando uma função | |
var Music = function(){ | |
} | |
var Song = new Music(); | |
//Construtores | |
var Music = function(singer){ | |
this.singer = singer; | |
}; | |
var song = new Music('Raul Seixas'); | |
//Funções - Primeiro Modo | |
var Music = function(singer){ | |
this.singer = singer; | |
this.singerName = function(){ | |
console.log(this.singer); | |
}; | |
}; | |
var song = new Music('Chuck Berry'); | |
song.singerName(); //Escreve Chuck Berry | |
//Funções - Segundo Modo | |
var Music = function(singer){ | |
this.singer = singer; | |
}; | |
Music.prototype = { | |
singerName: function(){ | |
console.log(this.singer); | |
}; | |
}; | |
var song = new Music('Hillbilly Rawhide'); | |
song.singerName(); //Escreve Hillbilly Rawhide | |
//Funções - Terceiro Modo | |
var Music = function(singer){ | |
this.singer = singer; | |
}; | |
Music.prototype.singerName = function(){ | |
console.log(this.singer); | |
} | |
var song = new Music('Matanza'); | |
song.SingerName(); //Escreve Matanza; |
This file contains hidden or 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
<?php | |
//Instanciando uma classe | |
class Music{ | |
} | |
$song = new Music(); | |
//Construtores | |
class Music{ | |
protected $singer; | |
public function __construct($singer){ | |
$this->singer = $singer; | |
} | |
} | |
$song = new Music('Raul Seixas'); | |
//Funções | |
class Music { | |
private $singer; | |
public function __construct($singer){ | |
$this->singer = $singer; | |
} | |
public function singerName(){ | |
echo $this->singer; | |
} | |
} | |
$song = new Music('Johnny Cash'); | |
$song->singerName(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment