Hi guys!

Thx Eric, I understand the ins and outs of prototypical inheritance in
handling scopes. I think that your example also is using my 1st approach,
which my current way of doing thigs. So I think that we are on the same
page here.

Thx Sander, I was looking for explanation like that! You are absolutely
right about passing primitives by value, I shouldn't use a primitive in my
example. I was writing this up in a hurry :-)

I *assumed* that the 2nd approach might be a bit faster, because if the
whole object would have changed, then it would be enough to notice
different references (for instance: old *usersArray* was using #1234
reference, the new one is #4567, so we already know that the scope is dirty
without checking array elements).

Good point about the new "controller as" syntax, but I think that you can
still have the same doubts about attaching model to *this* reference. Or
perhaps the "dot in model" does not apply to this new approach? Frankly,
inheritance won't be a problem here anymore, so perhaps Angular team would
prefer to bind model to *this* directly?

You guys made me think that I'm not doing anything wrong, but I think that
I would rest assured if I found some info about it in the official Angular
documentation.

Best regards,
Łukasz Bachman

2014-10-11 8:05 GMT+02:00 Sander Elias <[email protected]>:

> Hi Łukasz,
>
>
>>    - does either of the solutions hides some bugs or flaws?
>>
>> No, it’s basically exactly the same thing. However, I think the second
> approach might confuse you. let me explain.
> you decide to do some assigning in your controller, like setting the
> selectedUserIs so you do in your controller:
> selectedUserId = fetchAUser();. This will not update
> $scope.model.selectUserId. You have to remember that
> JavaScript primitives
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals>,
> are never passed by reference.
>
>
>>    - is the overhead of watching the scope is higher/lower in any case
>>    (performance implications)?
>>
>> No. As I said, it is exactly the same thing. there is no difference in
> the $scope. All that you have done is
> put some extra visual clues in your code. with exception of the primitives
> as mentioned above. those will
> consume some extra memory (the extra reference to the array will do to,
> but this is such a small amount,
> you can safely ignore that)
>
>
>>    - is there any recommended way of doing this?
>>
>> Your first way is the recommend way if you still want to use $scope. The
> current recommend way is to
> use the controllerAs syntax, in where the $scope inheritance is mostly
> mitigated.
> I created a sample plunk here <http://goo.gl/rEqT53>, that I created for
> someone that needed localized events. There are a
> couple of controllers in there that follow the new recommend way.
> When you have any questions left, don’t’ hesitate to ask!
>
> Regards
> Sander
> ​
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/zAjgjeyWptI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to