Chrome DevTools为什么不显示对象的所有属性?

时间:2018-12-05 22:02:38

标签: angularjs google-chrome-devtools angularjs-controller

这是在断点处捕获的Chrome DevTools的屏幕截图。

正如我在注释中所指出的,“监视”窗格显示变量markerClusterer具有属性clearMarkers,但是在“范围”窗格中,该属性未在任何地方列出。

为什么?

如果有所作为,那么我使用的是AngularJS 1.7.5框架,这部分代码在控制器中。屏幕快照下方粘贴了代码。我不需要有关角度样式或最佳做法的任何评论-这只是基于在线演示的概念证明。我只是发布代码以防它有助于解释DevTools为什么不显示所有存在的属性。

a property is not visible in Chrome DevTools Scope pane

<!DOCTYPE html>
<html ng-app="myApp">

<head>
    <title>Dynamic ngMap demo</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>

</head>

<body>

<div ng-controller="mapController">
    <div map-lazy-load="https://maps.google.com/maps/api/js?key=hidden" ng-if="show()">

        <map zoom="2" center="[43.6650000, -79.4103000]">

        </map>
    </div>
    <button ng-click="update()">update</button>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"
        integrity="sha256-7/yoZS3548fXSRXqc/xYzjsmuW3sFKzuvOCHd06Pmps=" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.js"
        integrity="sha256-RflTGBQTyWuRHcjjgRTBrkLLntUWrNMmqMBV6vB7+Lw=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/ngmap@1.18.5/build/scripts/ng-map.js"
        integrity="sha256-n5o9oKQB0Zkoty1KgnVig31eV4ceJzLWtzWAq6E2gqs=" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/markerclustererplus/2.1.4/markerclusterer.js"
        integrity="sha256-NcAKtiP/C7H0jWpFCoXdc0Oi6DMIyXTc3yhyF6F9efI=" crossorigin="anonymous"></script>

<script>

  MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_ = 'https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m';  //changed image path
</script>

<!-- scripts/markers.js just defines an array:
var markers = [...]
-->
<script src="scripts/markers.js"></script>
<script>
  var app = angular.module('myApp', ['ngMap']);

  app.controller('mapController', function ($scope, $http, $interval, NgMap, $timeout) {

    $scope.dynMarkers = [];

    function data() {
      return _.sampleSize(markers, 1000)
    }

    var markerClusterer;

    function update() {

      if (_.isFunction(_.get(markerClusterer, 'clearMarkers'))){
        markerClusterer.clearMarkers();
      }
      showing = false;
      showing = true;

      let sampled = data();
      $scope.dynMarkers = [];

      NgMap.getMap().then(function (map) {

        for (var i = 0; i < 1000; i++) {
          var latLng = new google.maps.LatLng(sampled[i].position[0], sampled[i].position[1]);

          let marker = new google.maps.Marker({position: latLng});
          console.log(marker);
          $scope.dynMarkers.push(marker);

        }

        markerClusterer = new MarkerClusterer(map, $scope.dynMarkers, {});

      });


    }

    update();

    _.extend($scope, {
      update,
      markerClusterer
    });
  });


</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我在编写问题时就知道了...

展开__proto__显示缺少的属性!

enter image description here