JavaScript OOP and asynchronous methods from Chrome extension api -


i making chrome extension , uses little blocks of text. made class , each block instance of class. such that:

function block(bid){     var block = object.create(block.prototype);     block.title = "default"     block.content = "";     block.bid = bid;     return block; };  block.prototype.settitle = function (){     chrome.tabs.query({currentwindow: true, active: true}, function(tabs){         this.title = tabs[0].title;     }); }; 

my problem when call settitle() on block object title property isn't being changed method; stays @ "default". know has synchronous , async methods lost on going fixing this.

any appreciated!

to avoid further discussion, assumption it's scoping issue. try wit following code:

function block(bid){     var block = object.create(block.prototype);     block.title = "default"     block.content = "";     block.bid = bid;     return block; };  block.prototype.settitle = function (){      var callback = function(tabs) {         this.title = tabs[0].title;     }      chrome.tabs.query({currentwindow: true, active: true}, callback.bind(this)); }; 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -