Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/labs/object/object.js
2868 views
1
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview A labs location for functions destined for Closure's
17
* {@code goog.object} namespace.
18
* @author [email protected] (Chris Henry)
19
*/
20
21
goog.provide('goog.labs.object');
22
23
24
/**
25
* Whether two values are not observably distinguishable. This
26
* correctly detects that 0 is not the same as -0 and two NaNs are
27
* practically equivalent.
28
*
29
* The implementation is as suggested by harmony:egal proposal.
30
*
31
* @param {*} v The first value to compare.
32
* @param {*} v2 The second value to compare.
33
* @return {boolean} Whether two values are not observably distinguishable.
34
* @see http://wiki.ecmascript.org/doku.php?id=harmony:egal
35
*/
36
goog.labs.object.is = function(v, v2) {
37
if (v === v2) {
38
// 0 === -0, but they are not identical.
39
// We need the cast because the compiler requires that v2 is a
40
// number (although 1/v2 works with non-number). We cast to ? to
41
// stop the compiler from type-checking this statement.
42
return v !== 0 || 1 / v === 1 / /** @type {?} */ (v2);
43
}
44
45
// NaN is non-reflexive: NaN !== NaN, although they are identical.
46
return v !== v && v2 !== v2;
47
};
48
49