Last active
April 23, 2018 07:21
-
-
Save santhosh17s/4c421f5205a9ffd9cfc9f4eee03782f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Simple Class function | |
function API() { | |
this.name = 'This is API name'; | |
} | |
//prototype function for share between the object | |
API.prototype.getName = function() { | |
//Take copy of this keyword | |
var self = this; | |
return new Promise( function(resolve, reject){ | |
resolve(self.name); | |
//resolve(this); // [Object window] | |
}); | |
} | |
//for Fat-Arrow function with this keyword | |
API.prototype.getNamewithArrowFun = function() { | |
return new Promise( (resolve, reject) => { | |
resolve(this.name); | |
//resolve(this); // [Object window] | |
}); | |
} | |
//create object using new keyword. It is a constructor function. | |
var api = new API(); | |
api.getName().then( data => console.log(data)); //"This is API name" | |
api.getNamewithArrowFun().then( data => console.log(data)); //"This is API name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment