summaryrefslogtreecommitdiff
path: root/doc/Lang.md
blob: 9056eee30a581cc7be8b218dec4113cb42388566 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Lang

The `Lang` module is a collection of deprecated features that have been
completely superseded by standard ECMAScript. It remains a part of GJS for
backwards-compatibility reasons, but should never be used in new code.

#### Import

> Attention: This module is not available as an ECMAScript Module

The `Lang` module is available on the global `imports` object:

```js
const Lang = imports.lang
```

### Lang.bind(thisArg, function, ...args)

> Deprecated: Use [`Function.prototype.bind()`][function-bind] instead

Type:
* Static

Parameters:
* thisArg (`Object`) — A JavaScript object
* callback (`Function`) — A function reference
* args (`Any`) — A function reference

Returns:
* (`Function`) — A new `Function` instance, bound to `thisArg`

Binds a function to a scope.

[function-bind]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

### Lang.Class(object)

> Deprecated: Use native [JavaScript Classes][js-class] instead

Type:
* Static

Parameters:
* object (`Object`) — A JavaScript object

Returns:
* (`Object`) — A JavaScript class expression

...

Example usage:

```js
const MyLegacyClass = new Lang.Class({
    _init: function() {
        let fnorb = new FnorbLib.Fnorb();
        fnorb.connect('frobate', Lang.bind(this, this._onFnorbFrobate));
    },

    _onFnorbFrobate: function(fnorb) {
        this._updateFnorb();
    }
});
```

[js-class]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes

### Lang.copyProperties(source, dest)

> Deprecated: Use [`Object.assign()`][object-assign] instead

Type:
* Static

Parameters:
* source (`Object`) — The source object
* dest (`Object`) — The target object

Copy all properties from `source` to `dest`, including those that are prefixed
with an underscore (e.g. `_privateFunc()`).

[object-assign]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

### Lang.copyPublicProperties(source, dest)

> Deprecated: Use [`Object.assign()`][object-assign] instead

Type:
* Static

Parameters:
* source (`Object`) — The source object
* dest (`Object`) — The target object

Copy all public properties from `source` to `dest`, excluding those that are
prefixed with an underscore (e.g. `_privateFunc()`).

[object-assign]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

### Lang.countProperties(object)

> Deprecated: Use [`Object.assign()`][object-assign] instead

Type:
* Static

Parameters:
* object (`Object`) — A JavaScript object

[object-assign]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

### Lang.getMetaClass(object)

Type:
* Static

Parameters:
* object (`Object`) — A JavaScript object

Returns:
* (`Object`|`null`) — A `Lang.Class` meta object

...

### Lang.Interface(object)

> Deprecated: Use native [JavaScript Classes][js-class] instead

Type:
* Static

Parameters:
* object (`Object`) — A JavaScript object

Returns:
* (`Object`) — A JavaScript class expression

...

[js-class]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes