V
V
Vladimir T.2015-01-06 08:18:46
JavaScript
Vladimir T., 2015-01-06 08:18:46

What is the result of this assignment?

I found the following code in the source code of the service:
var self = $rootScope.$service_name = this;
$service_name - the service itself. Can you tell me what this code does? Puts a service instance in $rootScope and assigns it to self? Why is such a trick needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-01-06
@vachuahe

Why assign a service object to $rootScope - I don't know. Probably some kind of global helper.
Assignment to self - not to lose context in callbacks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question