2016-08-24 59 views
-1

所需輸出: -我應該添加什麼代碼才能使用JavaScript顯示以下輸出?

錯誤:您已斷開連接!

警告:你已經閒置15分鐘後

// Code starts here 

// Do not edit this function 

function output(msg) { 

    console.log(this.type, ":", msg) 

} 

// You may edit below this line not including the .output functions. 

var errorMsg = ; 

var warningMsg = ; 

// Do not edit below this line. 

errorMsg.output('You have been disconnected!'); 

warningMsg.output('You have been idle for 15 minutes'); 
+1

請重新格式化您的代碼並編輯您的問題。你想顯示特定網站上的錯誤或最新情況? –

+0

@LajosArpad不作業的傢伙,我只是想學習一些新的東西,並從互聯網上解決一些問題..... :) –

回答

1

您可以使用函數作爲您的errorMsgwarningMsg的構造函數是這樣的:

var Logger = function(type) { 
    this.type = type 
    this.output = output 
} 

var errorMsg = new Logger('warning'); 
var warningMsg = new Logger('error'); 

這裏是一個working plunker 如果您有任何其他問題,隨時問。

+0

其實我需要使用已經在問題中定義的功能,並獲得所需的輸出 –

+0

@AvneetSangha這是使用你的功能。 'this.ouput = output'只是將你的函數包裝到構造函數中 – Okazari

+0

@Okazari ....哦,是啊,我的壞...謝謝你的幫助....欣賞它.. !!! –

0

我不知道你正在尋找這樣的:

//Desired Output:- 
 

 
console.error("You have been disconnected!") 
 

 
console.warn("You have been idle for 15 minutes"); 
 

 
console.log("Code starts here") 
 

 
// Do not edit this function 
 

 
function output(msg) { 
 

 
console.log(this.type, ":", msg) 
 
}

相關問題