views:

56

answers:

2

I am making a reference to the Javascript function splice() on an array and I get the error:

"Cannot make a static reference to the non-static function splice()"

What's going on - how is this a static reference, aren't I referencing an instance of an Array class and its method - how is that static?

$(document).ready( function() {

var queryPreds = new Array();
var queryObjs = new Array();    

function remFromQuery(predicate) {
    for(var i=0; i<arrayName.length;i++ ) { 
        if(queryPreds[i]==predicate)
        queryPreds.splice(i,1);
        queryObjs.splice(i,1);
        }
    }
}
+4  A: 

That error message is a Java compiler error message, rather than a Javascript interpreter message. Are you using an environment (like Eclipse or something) that might be mistakenly thinking you're writing in Java rather than Javascript? If you're using Eclipse, perhaps you're running into this bug, which has been fairly recently fixed.

T.J. Crowder
+2  A: 

Sorry, I don't have a direct answer, but I can offer these notes...

  • Could benefit from shorthand $(function() { }); for document ready and [] for array literal
  • arrayName in that function is not defined, is it defined elsewhere?
  • You need to close your argument list you send to $(document).ready() with a closing parenthesis )
  • Your indentation is confusing
  • That if statement will only run the line immediately under it
alex