This file contains 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
function pdv(OPERACIJA) { | |
return function (broj) { | |
if ( OPERACIJA === '-' ) { | |
return broj - 20; | |
} else if( OPERACIJA === '+' ) { | |
return broj + 20; | |
} else { | |
throw 'Lose uneti parametri!'; | |
} | |
} |
This file contains 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 data = { | |
first_name: "Vladimir", | |
last_name: "Sljubura", | |
age: "unknown", | |
username: "Slju" | |
}; | |
validator.config = { | |
first_name: 'required', | |
age: 'numeric', |
This file contains 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
// Constructor | |
function Sale(price) { | |
this.price = price || 10 | |
} | |
Sale.prototype.getPrice = function () { | |
return this.price; | |
}; | |
Sale.decorators = {}; | |
Sale.decorators.statetax = { |
This file contains 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 agg = (function () { | |
var index = 0, | |
data = [1,2,3,4,5], | |
length = data.length; | |
return { | |
next: function () { |
This file contains 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
function CarMaker() {} | |
CarMaker.prototype.drive = function () { | |
return "Vroom, I have " + this.doors + " doors"; | |
}; | |
CarMaker.factory = function (type) { | |
var constr = type, | |
newcar; | |
if (typeof CarMaker[constr] !== "function") { |
This file contains 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
function object(o) { // Simple prototypal inheritance | |
function Proxy() {} | |
Proxy.prototype = o; | |
return new Proxy(); | |
} | |
function Person() { | |
this.name = "Vladimir" | |
} | |
Person.prototype.getName = function () { |
This file contains 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
// Pattern to avoid inheritance via prototype | |
var klass = function (Parent, props) { | |
var Child, Proxy, i; | |
Child = function () { | |
if (Child.uber && Child.uber.hasOwnProperty("__construct")) { // Check if Child has own constructor in context of superclass | |
Child.uber.__construct.apply(this, arguments); | |
} |
This file contains 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
// Inheritance using proxy | |
function inherit(Child, Parent) { | |
var Proxy = function () {}; | |
Proxy.prototype = Parent.prototype; // Set Proxy | |
Child.prototype = new Proxy(); // Inherit from Parent via Proxy | |
Child.superclas = Parent.prototype; // Allow access to Parent | |
Child.prototype.constructor = Child; // Set Child constructor to not point to Parent constructor | |
} |
This file contains 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
// Pattern to inherit both the properties and methods | |
function Parent(name) { | |
this.name = name || "Vladimir"; | |
} | |
Parent.prototype.say = function () { | |
return this.name; | |
}; | |
function Child(name) { | |
Parent.apply(this, arguments); |
This file contains 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
// Multiple inheritance with rent-a-constructor | |
function Human() { | |
this.starfleet = true; | |
this.enterprize = true; | |
} | |
function Klingon() { | |
this.empire = true; | |
this.warbird = true; | |
} | |
function Worf() { |
NewerOlder