Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建';链接';带有中间层的JavaScript API';流利';废话?_Javascript_Oop_Methods_Chaining - Fatal编程技术网

如何创建';链接';带有中间层的JavaScript API';流利';废话?

如何创建';链接';带有中间层的JavaScript API';流利';废话?,javascript,oop,methods,chaining,Javascript,Oop,Methods,Chaining,我正在创建JSSDK,在这里我正在寻找创建用户(API)/用户调用函数,如 var user = new user(); user.message.to("username").get.friendlist(function(data){ //process data received from callback. }); 现在,我知道方法链接是可以做到的,我可以做一些类似的事情 function User(Name) { this.uname = Name; } User

我正在创建JSSDK,在这里我正在寻找创建用户(API)/用户调用函数,如

var user = new user();

user.message.to("username").get.friendlist(function(data){
    //process data received from callback.
});
现在,我知道方法链接是可以做到的,我可以做一些类似的事情

function User(Name) {
    this.uname = Name;
}

User.prototype = {
    constructor: User,

    MessageTo: function (username) {
        this.uname = username;
        return this;
    },

    getFriendList: function (callback) {
        callback("My list");
    }
}
在创建User()的对象后,我可以如下使用它:

但是我不知道如何获得像我所寻找的那样的方法调用

user.message.to("username").get.friendlist(function(data){
});

埃文:我不确定这是否可能。非常感谢您的帮助和指点。

正如其他成员所评论的,做同样的事情还有其他选择,但我必须按照我需要的方式来做,这就是我们如何做到的

此解决方案符合我的要求,因此可能不适合其他情况

sdk.js

var User = function(){
UserName = null;
this.message = {

to : function(uname){

  UserName = uname   
  alert('called to '+uname);

  this.get = {
    friendlist : function(callback){
      console.log('called friendlist');
        callback('Hello friendlist :: '+ UserName);
    }
  }
  return this;
  }
  };
}
像这样使用它

  var user1 = new User();

  user1.message.to('H.Mahida').get.friendlist(function(data){
      alert('call back says '+ data);
  });
这里是链接到


希望它可能是有用的一些人或指导在同一个方向

您能告诉我们您是如何制作
getFriendList
链接示例的吗?对我来说
.get('friendlist',函数(数据){
更有意义。@Bergi请查看更新。!@Vohuman,是的,这是一个选项,但我必须以其他方式来做…!!可能重复或
  var user1 = new User();

  user1.message.to('H.Mahida').get.friendlist(function(data){
      alert('call back says '+ data);
  });