javascript - jhint error W021: 'draw' is a function -


i have included file in angular app .

/**  * @description google chart api directive module angularjs  * @version 0.1  * @author nicolas bouillon <nicolas@bouil.org>  * @license mit  * @year 2013  */ (function(document, window) {   'use strict';    function loadscript(url, callback) {     var script = document.createelement('script');     script.src = url;     script.onload = callback;     script.onerror = function() {       throw new error('error loading "' + url + '"');     };      document.getelementsbytagname('head')[0].appendchild(script);   }     angular.module('directive.googlechart', [])    .constant('googlechartapiconfig', {     version: '1',     optionalsettings: {       packages: ['corechart']     }   })    .factory('googlechartapiproxy', ['$rootscope', '$q', 'googlechartapiconfig',     function($rootscope, $q, apiconfig) {       var apiready = $q.defer(),         onload = function() {           // override callback function           var settings = {             callback: function() {               var oldcb = apiconfig.optionalsettings.callback;               $rootscope.$apply(function() {                 apiready.resolve();               });                if (angular.isfunction(oldcb)) {                 oldcb.call(this);               }             }           };            settings = angular.extend({}, apiconfig.optionalsettings, settings);            window.google.load('visualization', apiconfig.version, settings);         };        loadscript('//www.google.com/jsapi', onload);        return function(fn, context) {         var args = array.prototype.slice.call(arguments, 2);         return function() {           apiready.promise.then(function() {             fn.apply(context, args.concat(array.prototype.slice.call(arguments)));           });         };       };     }   ])    .directive('googlechart', ['$timeout', '$window', 'googlechartapiproxy',     function($timeout, $window, apiproxy) {       return {         restrict: 'a',         scope: {           chart: '=chart'         },         link: function($scope, $elm, $attr) {           // watches, refresh chart when data, title or dimensions change           $scope.$watch('chart', function() {             draw();           }, true); // true deep object equality checking            // redraw chart if window resized            angular.element($window).bind('resize', function() {             draw();           });            function draw() {             if (!draw.triggered && ($scope.chart !== undefined)) {               draw.triggered = true;               $timeout(function() {                 draw.triggered = false;                 var datatable = new google.visualization.datatable($scope.chart.data, 0.5);                  var chartwrapperargs = {                   charttype: $scope.chart.type,                   datatable: datatable,                   view: $scope.chart.view,                   options: $scope.chart.options,                   containerid: $elm[0]                 };                  if ($scope.chartwrapper == null) {                   $scope.chartwrapper = new google.visualization.chartwrapper(chartwrapperargs);                   google.visualization.events.addlistener($scope.chartwrapper, 'ready', function() {                     $scope.chart.displayed = true;                   });                   google.visualization.events.addlistener($scope.chartwrapper, 'error', function(err) {                     console.log("chart not displayed due error: " + err.message);                   });                 } else {                   $scope.chartwrapper.setcharttype($scope.chart.type);                   $scope.chartwrapper.setdatatable(datatable);                   $scope.chartwrapper.setview($scope.chart.view);                   $scope.chartwrapper.setoptions($scope.chart.options);                 }                  $timeout(function() {                   $scope.chartwrapper.draw();                 });               }, 0, true);             }           }            draw = apiproxy(draw, this);         }       };     }   ]);  })(document, window); 

when doing grunt build gives error @ line

the error

[l123:c11] w021: 'draw' function.           draw = apiproxy(draw, this); 

i have tried changing variable name , , putting var before , doesn't solve problem , please suggest solution .

jshint raises "{a} function" warning when attempt assign value identifier first appeared part of function declaration:

function draw() {     // ... }  draw = apiproxy(draw, this); 

i'm not entirely sure of reasoning behind warning (jslint warns in situation, message "read only" instead).

you can fix using different identifier function declaration:

function drawfn() {     // ... }  var draw = apiproxy(drawfn, this); 

however, recommend not including third-party scripts in jshint section of grunt file.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -