diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 84dee5b57a08..a0f8f45d3969 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -1029,25 +1029,33 @@ function $RootScopeProvider(){ * @return {Object} Event object (see {@link ng.$rootScope.Scope#$on}). */ $emit: function(name, args) { + function Event(currentScope) { + this.name = name; + this.currentScope = currentScope; + this.targetScope = target; + this.defaultPrevented = globalDefaultPrevented; + } + Event.prototype.preventDefault = function() { + // Deals with the current instance (this) and also the next ones with globalDefaultPrevented. + this.defaultPrevented = true; + globalDefaultPrevented = true; + }; + Event.prototype.stopPropagation = function() { + stopPropagation = true; + }; + var empty = [], namedListeners, + target = this, scope = this, stopPropagation = false, - event = { - name: name, - targetScope: scope, - stopPropagation: function() {stopPropagation = true;}, - preventDefault: function() { - event.defaultPrevented = true; - }, - defaultPrevented: false - }, - listenerArgs = concat([event], arguments, 1), + globalDefaultPrevented = false, + event = new Event(scope), + listenerArgs, i, length; do { namedListeners = scope.$$listeners[name] || empty; - event.currentScope = scope; for (i=0, length=namedListeners.length; i