904 if (l == 's') { d.s = v[i] }
905 }
906
907 var o = new Date(d.y, Number(d.m) - 1, d.d, Number(d.h), Number(d.n), Number(d.s), 0)908 const y = String(o.getFullYear()) + '-'
909 const m = nuPad2(o.getMonth() + 1) + '-'
910 const a = nuPad2(o.getDate()) + ' '
879 .nuReplaceAll(',', ' ')
880 .split(' ')
881
882 var o = Date().toString().split(' ', 6) // -- Tue Sep 07 2004 11:11:12 GMT+0930 (Cen. Australia Standard Time)883 const time = String(o[4]).split(':')
884
885 const d = { y: o[3], m: FMT[nuTranslateToEnglish(o[1])].jsmonth, d: o[2], h: time[0], n: time[1], s: time[2] } // -- today's date time[2]}; //-- today's date
789 }
790
791 if (t[0] == 'undefined') {
792 var t = [0, 0, 0]793 }
794
795 const o = new Date(d[0], d[1] - 1, d[2], t[0], t[1], t[2], 0) // -- (year, month, day, hours, minutes, seconds, milliseconds)
785 var t = String(v.split(' ')[1]).split(':')
786 } else {
787 var d = [0, 0, 0]
788 var t = String(v.split(' ')[0]).split(':')789 }
790
791 if (t[0] == 'undefined') {
784 var d = String(v.split(' ')[0]).split('-')
785 var t = String(v.split(' ')[1]).split(':')
786 } else {
787 var d = [0, 0, 0]788 var t = String(v.split(' ')[0]).split(':')
789 }
790
782
783 if (v.includes('-')) {
784 var d = String(v.split(' ')[0]).split('-')
785 var t = String(v.split(' ')[1]).split(':')786 } else {
787 var d = [0, 0, 0]
788 var t = String(v.split(' ')[0]).split(':')
781 const FMT = this.setFormats()
782
783 if (v.includes('-')) {
784 var d = String(v.split(' ')[0]).split('-')785 var t = String(v.split(' ')[1]).split(':')
786 } else {
787 var d = [0, 0, 0]
682 }
683
684 if (nd == 0) { // -- no deleting allowed
685 for (var i = 0; i < o.rows.length; i++) {686 o.deleted[i] = 0
687 }
688
671 titles.shift()
672 o.chartData.splice(0, 0, titles)
673
674 for (var i = 0; i < o.chartData[0].length; i++) {675 row = []
676
677 for (let p = 0; p < o.chartData.length; p++) {
652 }
653
654 for (var i = 0; i < o.rows.length; i++) {
655 var row = JSON.parse(JSON.stringify(o.rows[i]))656
657 row.shift()
658 row.pop()
651 o.columns.push(c)
652 }
653
654 for (var i = 0; i < o.rows.length; i++) {655 var row = JSON.parse(JSON.stringify(o.rows[i]))
656
657 row.shift()
572 pk = $('#nuRECORD').attr('data-nu-primary-key-name')
573 table = $('#nuRECORD').attr('data-nu-table')
574 sel = '#nuRECORD'
575 var sf = 'nuRECORD'576
577 if (table === undefined) {
578 oi = parent.nuFORM === undefined ? undefined : parent.nuFORM.getCurrent().form_id
478 const SF = d[i]
479 if (SF.id == subform_name) { // -- i've got the right subform
480 // var fmt = $("[id$='" + field_name + "']input[id^='" + subform_name + "']").attr('data-nu-format')
481 var f = SF.fields.indexOf(field_name) // -- check for valid field(column)482 if (f == -1) { return 0 }
483 for (let c = 0; c < SF.rows.length; c++) {
484 if (SF.deleted[c] == 0) { // -- add up only stuff not being deleted
471 }
472
473 const d = this.data() // -- an array of all data as subforms (the mainform is the first element)
474 var v = 0475 let u = 0
476
477 for (let i = 0; i < d.length; i++) {
465 } else {
466 const o = $('#' + field)
467 var f = o.attr('data-nu-format')
468 var v = o.val()469
470 return nuFORM.removeFormatting(v, f)
471 }
464 var field_name = field.split('.')[1]
465 } else {
466 const o = $('#' + field)
467 var f = o.attr('data-nu-format')468 var v = o.val()
469
470 return nuFORM.removeFormatting(v, f)
461 calc (field) {
462 if (field.split('.').length == 2) {
463 var subform_name = field.split('.')[0]
464 var field_name = field.split('.')[1]465 } else {
466 const o = $('#' + field)
467 var f = o.attr('data-nu-format')
460
461 calc (field) {
462 if (field.split('.').length == 2) {
463 var subform_name = field.split('.')[0]464 var field_name = field.split('.')[1]
465 } else {
466 const o = $('#' + field)
It is recommended to use let
or const
over var
.
This will help prevent re-declaration of variables that are in the global scope when using var
.
ES6 allows programmers to create variables with block scope instead of function scope using the let
and const
keywords.
Block scope is common in many other programming languages and helps programmers avoid mistakes such as this one:
var count = people.length;
var enoughFood = count > sandwiches.length;
if (enoughFood) {
var count = sandwiches.length; // accidentally overriding the count variable
console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
}
// our count variable is no longer accurate
console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");
Block scoped variables shadow outer declarations instead of writing to them.
NOTE: There are certain edge cases where users might want to consider var. Consider this example:
var lib = lib || { run: () => {} }
Here, lib
might be a library that is exposed to an HTML file using a <script>
tag.
The var
keyword helps avoid re-writing lib
if it has already been declared via an injected script that was executed before this one.
Ideally, you should let bundlers worry about cases like this.
But if you want to use var
anyway, consider using a skipcq comment, or disabling the issue altogether.
Bad Practice
var x = "y";
var CONFIG = {};
Recommended
let x = "y";
const CONFIG = {};