javascript - SyntaxError: function statement requires a name -
im confused error become without todo event click etc. yes used search here, in of cases found situation problem.
the "syntaxerror: function statement requires name" throwing firebug after pagerefresh here: ongoto:function(evt){
this function:
function examplefc(ctx){ 'use strict'; var goto = $('a[href*=#]',this.$ctx); goto.on('click',$.proxy(this.ongoto,this)); ongoto:function(evt){ evt.preventdefault(); var elem = $(evt.currenttarget).attr('href'); if(elem.length > 1){ $('html,body').animate({ scrolltop: $(elem).offset().top }, 700, function (){location.hash = elem;}); } return false; } };
whats wrong? want call function ongoto catching click event.
the syntax incorrect. syntax should used inside objects.
var obj = { ongoto: function(){ } } in areas other object should use syntax:
var ongoto = function( ) { }; // function declaration ongoto() // function call or, in case of code,
this.ongoto = function() {}; // function declaration this.ongoto(); // function call finally code should this:
function examplefc(ctx){ 'use strict'; var goto = $('a[href*=#]',this.$ctx); goto.on('click',$.proxy(this.ongoto,this)); this.ongoto = function(evt) { evt.preventdefault(); var elem = $(evt.currenttarget).attr('href'); if(elem.length > 1){ $('html,body').animate({ scrolltop: $(elem).offset().top }, 700, function (){location.hash = elem;}); } return false; } }
Comments
Post a Comment