4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 var Ap
= Array
.prototype;
23 var Fp
= Function
.prototype;
26 // PhantomJS doesn't support Function.prototype.bind natively, so
27 // polyfill it whenever this module is required.
28 Fp
.bind = function(context
) {
30 var args
= slice
.call(arguments
, 1);
33 var invokedAsConstructor
= func
.prototype && (this instanceof func
);
35 // Ignore the context parameter when invoking the bound function
36 // as a constructor. Note that this includes not only constructor
37 // invocations using the new keyword but also calls to base class
38 // constructors such as BaseClass.call(this, ...) or super(...).
39 !invokedAsConstructor
&& context
|| this,
40 args
.concat(slice
.call(arguments
))
44 // The bound function must share the .prototype of the unbound
45 // function so that any object created by one constructor will count
46 // as an instance of both constructors.
47 bound
.prototype = func
.prototype;