javascript - Capturing scope in directive while it's digesting—far more verbose than a console.log(scope) -
i've been using directive scope: false
investigate what's available directive has access parent's scope—i realized doing console.log(scope)
in linking function has been misleading.
.directive('directive', function() { return { scope: false; link: function (scope, elem, attrs) { console.log(scope); console.log($.extend({}, scope)); } });
the latter, console.log($.extend({}, scope));
, object far more verbose, assume being logged during $digest
phase, (as 1 of properties, $$phase
, has value of $digest
:-p).
the console.log($.extend({}, scope));
includes objects expect have access parent scope, objects on parent scope, don't appear in output console.log(scope)
.
so i'm assuming console.log($.extend({}, scope));
—actually housing available scope
in directive's linking function.
anyways, going on console.log(scope)
—what showing me exactly, , why 2 different?
any appreciated. thank you!
here example of output both:
i notice have different prototypes, not sure derive that. because of this, it's kind of murky available in directive's scope.
this isn't related $digests.
var verboseobject = $.extend({}, scope); console.log(verboseobject);
the above more verbose because properties angular's scope
prototype (which scope
inherits from) got copied verboseobject
. way jquery's $.extend
works: http://api.jquery.com/jquery.extend/
properties inherited object's prototype copied over
since properties not on verboseobject
prototype on object itself, developer tools shows flat object.
console.log(scope);
in above case, "missing" properties $digest
, $apply
, $eval
, on still available on scope
, further prototype chain. in developer tools can inspect prototype chain expanding __proto__
property of object. might have go few times reach actual scope
scope
inherits from.
Comments
Post a Comment