Last active
November 18, 2015 21:54
-
-
Save datamafia/f0a9df78ecad1ef0b4f1 to your computer and use it in GitHub Desktop.
Simple OOP reference for simple functionality across languages.
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
// 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 |
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
<? | |
// 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 |
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
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