Skip to content

Instantly share code, notes, and snippets.

@krmgns
Created January 29, 2015 08:41
Show Gist options
  • Save krmgns/e12e22324b8525b7d19e to your computer and use it in GitHub Desktop.
Save krmgns/e12e22324b8525b7d19e to your computer and use it in GitHub Desktop.
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