File: hash.js

package info (click to toggle)
pymol 2.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 43,312 kB
  • sloc: cpp: 480,106; python: 79,860; ansic: 28,343; javascript: 6,792; sh: 47; makefile: 30; csh: 8
file content (54 lines) | stat: -rw-r--r-- 1,655 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function Hash(){
    for( var i=0; i < arguments.length; i++ )
        for( n in arguments[i] )
            if( arguments[i].hasOwnProperty(n) )
                this[n] = arguments[i][n];
}

    // Hash.version = 1.00;    // Original version
    // Hash.version = 1.01;    // Added ability to initialize in the constructor
    // Hash.version = 1.02;    // Fixed document bug that showed a non-working example (thanks mareks)
    //Hash.version = 1.03;    // Removed returning this from the constructor (thanks em-dash)
    Hash.version = 1.04;    // Missed some 'var' declarations (thanks Twey)


    Hash.prototype = new Object();

    Hash.prototype.keys = function(){
        var rv = [];
        for( var n in this )
            if( this.hasOwnProperty(n) )
                rv.push(n);
        return rv;
    }

    Hash.prototype.length = function(){
        return this.keys().length();
    }

    Hash.prototype.values = function(){
        var rv = [];
        for( var n in this )
            if( this.hasOwnProperty(n) )
                rv.push(this[n]);
        return rv;
    }

    Hash.prototype.slice = function(){
        var rv = [];
        for( var i = 0; i < arguments.length; i++ )
            rv.push(
                ( this.hasOwnProperty( arguments[i] ) )
                    ? this[arguments[i]]
                    : undefined
            );
        return rv;
    }

    Hash.prototype.concat = function(){
        for( var i = 0; i < arguments.length; i++ )
            for( var n in arguments[i] )
                if( arguments[i].hasOwnProperty(n) )
                    this[n] = arguments[i][n];
        return this;
    }