Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Declaring A Method Outside The Constructor

/*for methods declared outside the constructor remember:
do not add a function/const..it is fn= ()=>{} and NOT const fn = ()=>{} if outside the constructor
access them in the constructor with this.methodName;
the same method CAN access this.name below.
They (method declared inside and outside) work.

*/
class Person
 {
constructor(name)
{
this.name = name;
const result = this.fn();
return result;
}

fn = async ()=>{
let r =await fetch('/test', {method: 'POST', body: JSON.stringify({name:this.name}), headers: {'Content-type': 'application/json; charset=UTF-8'}})
return  r.json();
} 
}

let p = 	 new Person("john smith");
let result = await p;

console.log(result.name);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Calculate sum of last column in dynamically added rows using javascript 
Javascript :: The JavaScript call() Method 
Javascript :: change dir npm run build 
Javascript :: check if first array contains all elements javascript 
Javascript :: An Array Of Functions With Parameter 
Javascript :: JavaScript get div height dynamically without jQuery 
Javascript :: how to get mempool transactions and decode with ethers js 
Javascript :: send a message in the first channel discord.js 
Javascript :: sweet alert for react 
Javascript :: check token balance of an address in js 
Javascript :: component rerendering when view port comes 
Javascript :: var logEvenNums = function(num) {}; 
Javascript :: express get, post, delete, put template 
Javascript :: Backbone With Express 
Javascript :: Simple Backbone Example 
Javascript :: document.getelementbyid add number 
Javascript :: xor two hex strings js 
Javascript :: set to array js 
Javascript :: number of factors 
Javascript :: javascript invert number 
Javascript :: connect react to backend 
Javascript :: how to upload file in node js 
Javascript :: sort include sequelize 
Javascript :: how to focus out of an input in testing library 
Javascript :: intersection array of object javascript 
Javascript :: jenkins javascript heap out of memory 
Javascript :: javascript + Operator with Numbers 
Javascript :: JavaScript pauses the async function until the promise 
Javascript :: actionscript fibonacci fibonaccinumbers 
Javascript :: javascript get days difference between two dates 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =