source: Dev/branches/rest-dojo-ui/client/dojox/collections/Stack.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.8 KB
Line 
1define(["dojo/_base/kernel", "dojo/_base/array", "./_base"], function(dojo, darray, dxc){
2/*=====
3var dxc = dojox.collections;
4=====*/
5        dxc.Stack=function(/* array? */arr){
6                //      summary
7                //      returns an object of type dojox.collections.Stack
8                var q=[];
9                if (arr) q=q.concat(arr);
10                this.count=q.length;
11                this.clear=function(){
12                        //      summary
13                        //      Clear the internal array and reset the count
14                        q=[];
15                        this.count=q.length;
16                };
17                this.clone=function(){
18                        //      summary
19                        //      Create and return a clone of this Stack
20                        return new dxc.Stack(q);
21                };
22                this.contains=function(/* object */o){
23                        //      summary
24                        //      check to see if the stack contains object o
25                        for (var i=0; i<q.length; i++){
26                                if (q[i] == o){
27                                        return true;    //      bool
28                                }
29                        }
30                        return false;   //      bool
31                };
32                this.copyTo=function(/* array */ arr, /* int */ i){
33                        //      summary
34                        //      copy the stack into array arr at index i
35                        arr.splice(i,0,q);
36                };
37                this.forEach=function(/* function */ fn, /* object? */ scope){
38                        //      summary
39                        //      functional iterator, following the mozilla spec.
40                        dojo.forEach(q, fn, scope);
41                };
42                this.getIterator=function(){
43                        //      summary
44                        //      get an iterator for this collection
45                        return new dxc.Iterator(q);     //      dojox.collections.Iterator
46                };
47                this.peek=function(){
48                        //      summary
49                        //      Return the next item without altering the stack itself.
50                        return q[(q.length-1)]; //      object
51                };
52                this.pop=function(){
53                        //      summary
54                        //      pop and return the next item on the stack
55                        var r=q.pop();
56                        this.count=q.length;
57                        return r;       //      object
58                };
59                this.push=function(/* object */ o){
60                        //      summary
61                        //      Push object o onto the stack
62                        this.count=q.push(o);
63                };
64                this.toArray=function(){
65                        //      summary
66                        //      create and return an array based on the internal collection
67                        return [].concat(q);    //      array
68                };
69        };
70        return dxc.Stack;
71});
Note: See TracBrowser for help on using the repository browser.