mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-29 05:15:38 +08:00
refactor($parse): change 'this' to a $parse keyword instead of scope field
BREAKING CHANGE: - $scope['this'] no longer exits on the $scope object - $parse-ed expressions no longer allow chaining 'this' such as this['this'] or $parent['this'] - 'this' in $parse-ed expressions can no longer be overriden, if a variable named 'this' is put on the scope it must be accessed using this['this'] Closes #9105
This commit is contained in:
@@ -51,8 +51,25 @@ describe('Scope', function() {
|
||||
|
||||
|
||||
describe('this', function() {
|
||||
it('should have a \'this\'', inject(function($rootScope) {
|
||||
expect($rootScope['this']).toEqual($rootScope);
|
||||
it('should evaluate \'this\' to be the scope', inject(function($rootScope) {
|
||||
var child = $rootScope.$new();
|
||||
expect($rootScope.$eval('this')).toEqual($rootScope);
|
||||
expect(child.$eval('this')).toEqual(child);
|
||||
}));
|
||||
|
||||
it('\'this\' should not be recursive', inject(function($rootScope) {
|
||||
expect($rootScope.$eval('this.this')).toBeUndefined();
|
||||
expect($rootScope.$eval('$parent.this')).toBeUndefined();
|
||||
}));
|
||||
|
||||
it('should not be able to overwrite the \'this\' keyword', inject(function($rootScope) {
|
||||
$rootScope['this'] = 123;
|
||||
expect($rootScope.$eval('this')).toEqual($rootScope);
|
||||
}));
|
||||
|
||||
it('should be able to access a variable named \'this\'', inject(function($rootScope) {
|
||||
$rootScope['this'] = 42;
|
||||
expect($rootScope.$eval('this[\'this\']')).toBe(42);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user