Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d219a57

Browse files
committed
perf($rootScope): change 'this' scope variable to a $parse keyword
1 parent 19871d2 commit d219a57

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/ng/parse.js

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ forEach({
9292
CONSTANTS[name] = constantGetter;
9393
});
9494

95+
//Not quite a constant, but can be lex/parsed the same
96+
CONSTANTS['this'] = function(self) { return self; };
97+
CONSTANTS['this'].sharedGetter = true;
98+
99+
95100
//Operators - will be wrapped by binaryFn/unaryFn/assignment/filter
96101
var OPERATORS = extend(createMap(), {
97102
/* jshint bitwise : false */

src/ng/rootScope.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function $RootScopeProvider(){
128128
this.$$phase = this.$parent = this.$$watchers =
129129
this.$$nextSibling = this.$$prevSibling =
130130
this.$$childHead = this.$$childTail = null;
131-
this['this'] = this.$root = this;
131+
this.$root = this;
132132
this.$$destroyed = false;
133133
this.$$asyncQueue = [];
134134
this.$$postDigestQueue = [];
@@ -212,7 +212,6 @@ function $RootScopeProvider(){
212212
}
213213
child = new this.$$ChildScope();
214214
}
215-
child['this'] = child;
216215
child.$parent = this;
217216
child.$$prevSibling = this.$$childTail;
218217
if (this.$$childHead) {

test/ng/rootScopeSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Scope', function() {
5252

5353
describe('this', function() {
5454
it('should have a \'this\'', inject(function($rootScope) {
55-
expect($rootScope['this']).toEqual($rootScope);
55+
expect($rootScope.$eval('this')).toEqual($rootScope);
5656
}));
5757
});
5858

0 commit comments

Comments
 (0)