1

I wrote this function and Firebug tells me that there is a Syntax error, I'm sure I'm doing something wrong with the "this".

function TituloRepetido(this){
    var es=false;
    for(var i=0; i<listaPeliculas.length; i++){
        var p=listaPeliculas[i];
        if(this==p['titulo']){
            es=true;
        }
    }
    return es;
}
4
  • What are you trying to do? What did you mean by 'this'? Commented Feb 21, 2014 at 23:00
  • I've answered your question, but you'll need to post more code to figure out your issue. Commented Feb 21, 2014 at 23:01
  • what is this? do you know? Commented Feb 21, 2014 at 23:01
  • Sorry for the mistakes, as I said I'm really new at this.. and I'm learning js and jQuery at the same time Commented Feb 22, 2014 at 18:24

3 Answers 3

4

this is a reserved keyword in javascript that refers to the instance in your current scope, which also means that you can't use it as a param.

Sign up to request clarification or add additional context in comments.

1 Comment

That makes sense admdrew, sorry.
2

this is a reserved word in js that is similar to 'this' in c# it refers to the current function object.

just change that word with something else:

function TituloRepetido(title){

    for(var i=0; i<listaPeliculas.length; i++){
        var p=listaPeliculas[i];
        if(title==p['titulo']){
            return true;
        }
    }
    return false;
}

current function is evaluating if title exists in lista de peliculas and returning a boolean

2 Comments

Although it could be made more efficient by returning early and eliminating the es variable.
Thanks! I'll try it. I use the es variable because they don't let me make functions with different return statements.
2

You can't use this as a parameter. It is a reserved word that refers to the instance of an object from within itself. Use a different parameter name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.