Добавил еще ведущие нули к миллисекундам, если кому-то еще когда-то этот код понадобится
log = function (text, color, define){ var id, time, thread, logHtml, textLog; define = (typeof define == 'string') ? define.split(/[\s,.|:;]+/g) : define; if(typeof define === 'object' && define !== null){ if(Array.isArray(define)){ id = define.indexOf('id') > -1; time = define.indexOf('time') > -1; thread = define.indexOf('thread') > -1; } else{ id = define.id == true; time = define.time == true; thread = define.thread == true; } } else id = time = thread = true; id = id ? '<a href="action://action' + ScriptWorker.GetCurrentAction() + '" style="color:gray;">[' + ScriptWorker.GetCurrentAction() + ']</a>' : ''; time = time ? ' ' + getTime() : ''; thread = thread ? ' Поток №' + thread_number() : ''; logHtml = (id || time || thread) ? id + '<span style="color: white">' + time + thread + ' : </span>' : ''; logHtml += '<span style="color:' + (color ? color : 'white') + '">' + text + '</span>'; textLog = '[' + ScriptWorker.GetCurrentAction() + ']' + time + thread + ' : ' + text function getTime(){ var checkTime = function(i){ return (i < 10) ? "0" + i : i; }; var checkMilliSeconds = function(ms){ if (ms < 10) { return "00" + ms; } else if (ms < 100) { return "0" + ms; } else { return ms; } }; var d = new Date(); var hh = checkTime(d.getHours()); var mm = checkTime(d.getMinutes()); var ss = checkTime(d.getSeconds()); var ms = checkMilliSeconds(d.getMilliseconds()); return '[' + hh + ':' + mm + ':' + ss + '.' + ms + ']'; }; Logger.WriteHtml(logHtml, textLog); }Попытка разложить классы в разные файлы
-
Хочу в разных файлах писать код класса и создание экземпляра.
Делаю в Node.js "создать новый файл" user
в нем пишу:exports.User= class { constructor() { console.log("UserTst"); } }А в "текущем" Node.js пишу:
'use strict'; let UserClass =await require("../user"); let User=New UserClass();И даже сохранить это не могу выдает ошибку.
Не удалось обновить: C:\Users\User\AppData\Roaming\BrowserAutomationStudio\apps\22.4.0\embedded\bac5c5b1.bBswiAmHJStD\distr\lib\custom\njv02lj10w.js:76 let User=New UserClass(); ^^^^^^^^^ SyntaxError: Unexpected identifier at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:588:28) at Object.Module._extensions..js (module.js:635:10) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12) at Function.Module._load (module.js:500:3) at Module.require (module.js:568:17) at require (internal/module.js:11:18) at C:\Users\User\AppData\Roaming\BrowserAutomationStudio\apps\22.4.0\embedded\bac5c5b1.bBswiAmHJStD\distr\lib\internal\custom.js:11:38Пробовал по разному ничего не получается.
На js мало писал. Привык к PHP и CPP, поэтому такой вопрос возник.
Подскажите, пожалуйста, можно ли это как-то заставить работать? -
@Dmitry33 said in Попытка разложить классы в разные файлы:
Подскажите пожалуйста, можно ли это как-то заставить работать.
Ага, изучить js, а потом лезть в ноду. А если серьезно конструктор вызывается через new а не New