How to create a ‘chaining’ JavaScript API with intermediate ‘fluent’ verbage?

I am creating js sdk, where I am looking for creating user (API)/ user call function like;

var user = new user();"username").get.friendlist(function(data){
    //process data received from callback.

Now, I know that method chaining can be done, and I am able to make something like

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

User.prototype = {
    constructor: User,

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

    getFriendList: function (callback) {
        callback("My list");

and I can use it as below after creating object of User();


But I have no Idea about how to get the method call like what I am looking for as;"username").get.friendlist(function(data){

Evan I am not sure if it is possible or not. Any help or pointer with same regards is appreciated.

Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.