Path: blob/trunk/third_party/closure/goog/labs/object/object.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview A labs location for functions destined for Closure's16* {@code goog.object} namespace.17* @author [email protected] (Chris Henry)18*/1920goog.provide('goog.labs.object');212223/**24* Whether two values are not observably distinguishable. This25* correctly detects that 0 is not the same as -0 and two NaNs are26* practically equivalent.27*28* The implementation is as suggested by harmony:egal proposal.29*30* @param {*} v The first value to compare.31* @param {*} v2 The second value to compare.32* @return {boolean} Whether two values are not observably distinguishable.33* @see http://wiki.ecmascript.org/doku.php?id=harmony:egal34*/35goog.labs.object.is = function(v, v2) {36if (v === v2) {37// 0 === -0, but they are not identical.38// We need the cast because the compiler requires that v2 is a39// number (although 1/v2 works with non-number). We cast to ? to40// stop the compiler from type-checking this statement.41return v !== 0 || 1 / v === 1 / /** @type {?} */ (v2);42}4344// NaN is non-reflexive: NaN !== NaN, although they are identical.45return v !== v && v2 !== v2;46};474849