diff --git a/src/Angular.js b/src/Angular.js index 5d9d2e12fffe..b100328d7097 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -2,6 +2,13 @@ //////////////////////////////////// +/** + * hasOwnProperty may be overriden by a property of the same name, or entirely + * absent from an object that does not inherit Object.prototype; this copy is + * used instead + */ +var hasOwn = Object.prototype.hasOwnProperty; + /** * @ngdoc function * @name angular.lowercase @@ -139,7 +146,7 @@ function forEach(obj, iterator, context) { if (obj) { if (isFunction(obj)){ for (key in obj) { - if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) { + if (key != 'prototype' && key != 'length' && key != 'name' && hasOwn.call(obj, key)) { iterator.call(context, obj[key], key); } } @@ -150,7 +157,7 @@ function forEach(obj, iterator, context) { iterator.call(context, obj[key], key); } else { for (key in obj) { - if (obj.hasOwnProperty(key)) { + if (hasOwn.call(obj, key)) { iterator.call(context, obj[key], key); } } @@ -162,7 +169,7 @@ function forEach(obj, iterator, context) { function sortedKeys(obj) { var keys = []; for (var key in obj) { - if (obj.hasOwnProperty(key)) { + if (hasOwn.call(obj, key)) { keys.push(key); } } @@ -508,7 +515,7 @@ function size(obj, ownPropsOnly) { return obj.length; } else if (isObject(obj)){ for (key in obj) - if (!ownPropsOnly || obj.hasOwnProperty(key)) + if (!ownPropsOnly || hasOwn.call(obj, key)) size++; } @@ -609,7 +616,7 @@ function shallowCopy(src, dst) { dst = dst || {}; for(var key in src) { - if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') { + if (hasOwn.call(src, key) && key.substr(0, 2) !== '$$') { dst[key] = src[key]; } } @@ -667,7 +674,7 @@ function equals(o1, o2) { keySet[key] = true; } for(key in o2) { - if (!keySet[key] && + if (!hasOwn.call(keySet, key) && key.charAt(0) !== '$' && o2[key] !== undefined && !isFunction(o2[key])) return false; diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js index 86b958148c40..eaf1cd2fae88 100644 --- a/src/angular-bootstrap.js +++ b/src/angular-bootstrap.js @@ -191,7 +191,7 @@ if (IGNORE[prop] || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing continue; - } else if (!globalVars.hasOwnProperty(varKey)) { + } else if (!hasOwn.call(globalVars, varKey)) { //console.log('new global variable found: ', prop); try { globalVars[varKey] = window[prop]; diff --git a/src/auto/injector.js b/src/auto/injector.js index d39e2aa9b7e6..75325c834e59 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -529,7 +529,7 @@ function createInjector(modulesToLoad) { if (typeof serviceName !== 'string') { throw Error('Service name expected'); } - if (cache.hasOwnProperty(serviceName)) { + if (hasOwn.call(cache, serviceName)) { if (cache[serviceName] === INSTANTIATING) { throw Error('Circular dependency: ' + path.join(' <- ')); } @@ -554,7 +554,7 @@ function createInjector(modulesToLoad) { for(i = 0, length = $inject.length; i < length; i++) { key = $inject[i]; args.push( - locals && locals.hasOwnProperty(key) + locals && hasOwn.call(locals, key) ? locals[key] : getService(key) ); diff --git a/src/loader.js b/src/loader.js index ecb166085460..43ef770ec208 100644 --- a/src/loader.js +++ b/src/loader.js @@ -65,7 +65,7 @@ function setupModuleLoader(window) { * @returns {module} new module with the {@link angular.Module} api. */ return function module(name, requires, configFn) { - if (requires && modules.hasOwnProperty(name)) { + if (requires && hasOwn.call(modules, name)) { modules[name] = null; } return ensure(modules, name, function() { diff --git a/src/ng/compile.js b/src/ng/compile.js index 6606dc6c6586..ec11eaadde1b 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -177,7 +177,7 @@ function $CompileProvider($provide) { this.directive = function registerDirective(name, directiveFactory) { if (isString(name)) { assertArg(directiveFactory, 'directive'); - if (!hasDirectives.hasOwnProperty(name)) { + if (!hasOwn.call(hasDirectives, name)) { hasDirectives[name] = []; $provide.factory(name + Suffix, ['$injector', '$exceptionHandler', function($injector, $exceptionHandler) { @@ -917,7 +917,7 @@ function $CompileProvider($provide) { */ function addDirective(tDirectives, name, location, maxPriority) { var match = false; - if (hasDirectives.hasOwnProperty(name)) { + if (hasOwn.call(hasDirectives, name)) { for(var directive, directives = $injector.get(name + Suffix), i = 0, ii = directives.length; i