Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- // Extend
- if (!Object.create) {
- Object.create = function (obj) {
- function f() { };
- f.prototype = obj;
- return new f();
- }
- }
- if (!Object.prototype.extend) {
- Object.prototype.extend = function (properties) {
- function f() { };
- f.prototype = Object.create(this);
- for (var prop in properties) {
- f.prototype[prop] = properties[prop];
- }
- f.prototype._super = this;
- return new f();
- }
- }
- // Prototypal OOP
- var Human = {
- init: function (fname, lname, age) {
- this.fname = fname;
- this.lname = lname;
- this.age = age;
- }
- };
- var Student = Human.extend({
- init: function (fname, lname, age, grade) {
- this._super.init(fname, lname, age);
- this.grade = grade;
- },
- introduce: function () {
- return "Hello! My name is " + this.fname + " " + this.lname + ", my age is: " + this.age + " grade: " + this.grade;
- }
- });
- var pesho = Object.create(Student);
- pesho.init("Pesho", "Mastikata", 12, 2);
- console.log(pesho.introduce());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement