Created
January 29, 2015 08:41
-
-
Save krmgns/e12e22324b8525b7d19e to your computer and use it in GitHub Desktop.
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
var Class = (function() { | |
return { | |
create: function(prototype){ | |
function Class() { | |
if (this.init && this.init.apply) { | |
this.init.apply(this, arguments); | |
} | |
} | |
Class.prototype = prototype; | |
Class.prototype.constructor = Class; | |
return Class; | |
}, | |
extend: function(target, properties) { | |
for (var i in properties) { | |
target.prototype[i] = properties[i]; | |
} | |
return target; | |
} | |
}; | |
})(); | |
// create | |
var Person = Class.create({ | |
firstName: null, | |
lastName: null, | |
// initializer | |
init: function(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
}, | |
getFullName: function() { | |
return this.firstName +" "+ this.lastName; | |
} | |
}); | |
// use | |
var person = new Person("Kerem", "Güneş"); | |
console.log(person.getFullName()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment