0

I am trying the following code. I want the html.concat(name) line to work. html is a string.

  function getName() {                                                      
    var name = fbName(function(name){                                         
      alert(html);  //works                                                        
      alert("getName: " + name);  //works
      html.concat(name);  //fails?                                   
      alert(html);  // failed: html remains unchanged                                            
    });                                                                     
  };                                                                          

  function fbName(callback){                                                  
    FB.api('/' + user_id + '?fields=name', function(response) {             
      callback(response.name);                                                
    });                                                                     
  };                                                                        
  getName();  
4

1 回答 1

0

js中的字符串是不可变的,所以html.concat(name);不会修改它的值, html而是返回一个新的字符串。改为使用html = html.concat(name);

于 2013-03-24T23:57:54.343 回答