Jump to content
php.lv forumi
  • 0

Javascript function


Question

Posted

Piemērs tieši no: https://www.npmjs.com/package/is-online

 

 

Apakša ExpressJs:

 

var isOnline = require('is-online');
 
isOnline(function(erronline) {
    console.log(online);
    //=> true 
});
 

 

 

 
ieliekot šo routes viss iet konsolē atgriež true vai false...
 
bet kā man pārrakstīt šo funkciju lai es viņu varētu lietot kā mainīgo..
 
piemēram

var networkStatuss = isOnline(function(err, online) {
    return online;
});



console.log(networkStatuss) // Atgriež undefined

2 answers to this question

Recommended Posts

  • 0
Posted

Tā nav sinhrona funkcija, lai tā darītu!

var isOnline = require('is-online')

var networkStatuss = () => {
	isOnline((err, online) => {
	console.log('1')	
	})
	console.log('2')
}

console.log(networkStatuss())

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...