Last active
January 3, 2017 15:38
-
-
Save diegolameira/79762aefc3e63a773778 to your computer and use it in GitHub Desktop.
Just a wrapper Class for LIFO, obviously Array.pop do the job standalone.
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 Stack = (function(){ | |
'use strict'; | |
// Class private shared vars | |
var place = 'kitchen'; | |
// Constructor | |
function Stack(some){ | |
// Instance private vars | |
var something = 'An instance private variable ' + some; | |
console.log('A new instance of Stack available', something); | |
// Instance public vars | |
this.items = new Array(); | |
} | |
Object.defineProperties(Stack.prototype, { | |
'place': { | |
enumerable: false, | |
configurable: false, | |
get: function(){ | |
return place; | |
}, | |
set: function(data){ | |
place = data; | |
} | |
}, | |
'length': { | |
enumerable: false, | |
configurable: false, | |
get: function(){ | |
return this.items.length | |
} | |
} | |
}) | |
Stack.prototype.add = function(item){ | |
return this.items.push(item); | |
} | |
Stack.prototype.get = function(idx){ | |
return !idx ? this.items.pop() : this.remove(idx); | |
} | |
Stack.prototype.list = function(){ | |
return this.items; | |
} | |
Stack.prototype.remove = function(idx){ | |
return this.items.splice(idx, 1); | |
} | |
return Stack; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment