Skip to content

Instantly share code, notes, and snippets.

@datamafia
Last active November 18, 2015 21:54
Show Gist options
  • Save datamafia/f0a9df78ecad1ef0b4f1 to your computer and use it in GitHub Desktop.
Save datamafia/f0a9df78ecad1ef0b4f1 to your computer and use it in GitHub Desktop.
Simple OOP reference for simple functionality across languages.
// class w/construct
var happy = function (msg) {
this.message = msg;
};
// method
happy.prototype.hello = function(){
console.log('hi');
console.log(this.message)
}
// instiante class
var h = new happy('yo')
// call method
h.hello()
// output
// hi
// yo
<?
// class
class happy{
var $message = 'hello';
// method (construct)
function __construct($msg){
$this->message = $msg;
}
// method
function hello(){
echo "hi\r\n";
echo $this->message;
}
}
// instiante
$h = new happy('yo');
// call method
$h->hello(); // hi yo
from __future__ import print_function
class Happy(object):
message = 'hello'
def __init__(self, msg):
self.message = msg
def hello(self):
print('hi')
print(self.message)
# instantiate
h = Happy('yo')
# call method
h.hello()
# hi
# yo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment