0

I have this code:

collection = (function() {

    function collection(removeLinkTitle){

        this.removeLinkTitle = removeLinkTitle || 'delete';
    }

    collection.prototype = {

        removeLinkTitle:        this.removeLinkTitle,

        init:function(){

            ...some code...
            this.deleteCollectionForm();
        },

        deleteCollectionForm:function(){

        var removeFormA = $('<a href="#">'+this.removeLinkTitle+'</a>');
        linkLi.append( removeFormA );

        removeFormA.on('click', function(e) {

            e.preventDefault();

            linkLi.remove();

            var index = collectionHolder.data( 'index' );
            collectionHolder.data( 'index', index - 1 );
        });
    }
};

return collection;

})();

The thing is that the var removeForm returns its value only the frst time it loads, the following times it returns undefined.

I don't want to pass the variable as an argument so, is it there any other way to do this?

Thanks !!

5
  • How are you calling it ?
    – mohkhan
    Commented Jul 19, 2013 at 9:32
  • Why do you declare a var when the function ends in the next line?
    – Thilo
    Commented Jul 19, 2013 at 9:32
  • really hard to tell something like this, i dont see where or when removeForm return something..?
    – reyaner
    Commented Jul 19, 2013 at 9:41
  • you could make removeForm global by defining var removeForm outside functions. Then (removing the word var inside the function), the value assigned to it will be available.
    – Sergio
    Commented Jul 19, 2013 at 9:48
  • @reyaner I am using it with an onclick event, like this removeForm.on('click', function(e) { linkLi.remove();}); Commented Jul 19, 2013 at 10:06

1 Answer 1

0

i think this is not really the problem, the one thing that is undefined is the, removeLinkTitle, try this:

return new collection;

so you hit your constructor, or set some other value with:

return new collection("delete item");

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.