Skip to content

Instantly share code, notes, and snippets.

@omarkdev
Last active July 5, 2016 21:19
Show Gist options
  • Save omarkdev/dc6e58d1a71f40c1f6a4ec0ec74a8823 to your computer and use it in GitHub Desktop.
Save omarkdev/dc6e58d1a71f40c1f6a4ec0ec74a8823 to your computer and use it in GitHub Desktop.
Prototype JS para PHP Developers
//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;
<?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