简体   繁体   中英

Understanding Hierarchy of the $scope in AngularJS?

When I create a object and navigate through the _proto__ property of it I get to know that it has been inherited from Object

在此处输入图片说明

Now when I create a new object and inherit the obj object, then I get the inheritance structure like this 在此处输入图片说明

Here i can understand that the object obj1 is being inherited from the object obj and the object obj is being inherited from the object Object, which is the global object.

Now my question is, when i debug in my console i get both obj and obj1 as Object but the when i debug the $scope of angularJS i get something like this

在此处输入图片说明

Why is the $scope returning b instead of Object which can be seen in all the two images above, what is so different in angularJS, am i missing something.

UPDATE 1

when I make a object of the constructor in javascript I get the function name in the constructor as shown in the image below

在此处输入图片说明

But in the case of the $scope i see no constructor function, why is that? am i missing something, please let me know

This is because you're debugging minified application.

$scope is an instance of internal Scope or ChildScope class .

In minified Angular bundle the class is called something like b .

When you inspect an object in console, it is referenced by this object's class name, for example:

function Scope() {}
var s = new Scope();

在此处输入图片说明

In your case, instead of function Scope() {} , in the minified version the code looks like this function b() {} and new b() is used instead of new Scope()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM