javascript use object property in functions within an object constructor

时间:2015-12-14 18:06:05

标签: javascript meteor

I would like to refer to the object property source inside collection.find().observe. I am aware that self and this are obviously referring to the wrong scope and wonder how to pass this.source to the function so I can call it at the console.log(...) lines.

Layer = function(collection) {
    this.source = new ol.source.Vector();

    collection.find().observe({
        added: function () {
            console.log(self.source)
            console.log(this.source)
        }
    });
};

0 个答案:

没有答案