How to update static int variable in javascript? [closed]

I tried to search a lot on google but can’t find the answer. That’s why asking here. This is my code.

class student {
  static i = 1;

  constructor(name) {
    this.studentName = name;
    this.studentRollno = this.i;
    student.i++;
  }

  into() {
    console.log(`Hello guys! My name is ${this.studentName} and my roll no. is ${this.studentRollno}. Nice to meet you.`);
  }
}

let a = new student("Nitigya Joshi");
a.into();

What I want to do is update the variable I whenever an object of student class is made to automatically assign roll no. serial-wise. But when I try to run this code, I get output but in place of roll no. it say’s undefined. Can’t figure out the error.

Output:

Hello guys! My name is Nitigya Joshi and my roll no. is undefined. Nice to meet you.

How to make a .env git push [closed]

ACCESS_TOKEN_SECRET=mvacorUQnOGuf9ngSoYjo46p9YufvaEZJW9oay4/d5Oqwv5bdtSM7TYgzt74E4vupL58f4uJIw2S4bBkzmfHFR8yY+9b2RLLHJsxYliHjBgHixMxnx0oaA4+TTptYPaPgK6EBfXxncNTvjyPSvXhNA4u25advGoVtfnFhc7iqzXJB6Ql1v4WCU7wm7DrbOcXhi1tkgJMAR/OoKZY+YDMJEbPR67bZhJMDj7O58GDtNcs0vjxCOahGkfSEPUTdVJDeHdmex1WUgAveRirqVfdeUnnvzR3V7aYteJjEwKP52oAvhkZYg2HCVL0ugo3pCbTtEvScgR6Xe1p1dYUAMZayA==

Expanding Text Area throws error on Chrome/Firefox but not Safari

I have a text area that dynamically expands to fit the content inputed. It works correctly on all browsers, as far as I can tell, but on FireFox and Chrome it gives this error in the console:

Uncaught TypeError: Cannot set properties of undefined (setting 'height') at oninput

Here’s the code with an example:

let ta = document.getElementsByTagName("textarea");

    for (let i = 0; i < ta.length; i++) {
        ta[i].setAttribute("style", "min-height:" + (ta[i].scrollHeight) + "px;overflow-y:hidden;");
        ta[i].addEventListener("input", oninput, false);
    

    function oninput() {
        this.style.height = "auto";
        let maxheight = 200;
        if (this.scrollHeight < maxheight){
            this.style.height = (this.scrollHeight) + "px";
        }else{
            this.style.height = maxheight + "px";
        }
    }
}
<textarea>type here...</textarea>

<br><br>

<input type="text" placeholder="This should not be affected">

I would like this code to run smoothly on all platforms. Additionally I want to make sure I am only targeting textarea and not input, as the error presents if I change a normal input as well.

getting error while adding css to button in my react js app

I was styling a button in my react js website and got this error while writing the css for it,
actually I was going to animate it after hovering the mouse. its showing the following errors

1.colon expected [11,9]
2.semi-colon expected [12,18]
3. { expected [13, 14]
4. at-rule or selector expected[15,5]
5. } expected [31,13]
6. identifier expected [34,19]
7. { expected [35,20]
8. at-rule or selector expected [36,9]

button{
    background: black;
    border: none;
    padding: 10px 20px;
    display: inline-block;
    font-size: 1rem;
    font-weight: 800;
    width: 200;
    cursor: pointer;
    transform: skew(-21deg);
    span{
        display: inline-block;
    transform: skew(21deg);

    }

    ::before{
        content: "";
        position: absolute;
        top: 0;
        bottom: 0;
        right: 100%;
        left: 100%;
        background: #000;
        opacity: 0;
        z-index: -1;
        transition: all 0.5s;
    }
    
    ::hover{
        color: #fff;
            ::before{
            left: 0;
            right:0;
            opacity: 1;
        }
    }
    
}

Why reduce method not work as expected in javascript?

I have an array that I want to convert to the key value. but it does not work correctly.

Here is my code:

const questionNumber = [1,2,3,4]

const options =
questionNumber.length > 0
  && questionNumber.reduce((arr, val) => ({

      ...arr,
      [val]: {answer: []},
    }))
 ;

console.log(options):

2: {answer: Array(0)}
3: {answer: Array(0)}
4: {answer: Array(0)}
[[Prototype]]: Object

But I want to be like:

1: {answer: Array(0)}
2: {answer: Array(0)}
3: {answer: Array(0)}
4: {answer: Array(0)}
[[Prototype]]: Object

Select2 doesn’t automatically set selected value on CentOS 7

I have a select2 to display list of timezone and automatically set selected value, codes below works properly in development environment (ASP MVC Net Core 3.1), Visual Studio 2019, but it doesn’t automatically set selected value when it runs on CentOS 7, strange for me, anybody can give me an advice?

$.ajax({
    headers: {
     api_key: '@PTX.Models.AppSettingsModel.Application.API_Key',
     api_secret: '@PTX.Models.AppSettingsModel.Application.API_Secret'
    },
    type: 'GET',
    url: getDeploymentPath() + '/User/Timezone/',
    dataType: 'json'
    }).done(function (data)
    {
        result = $.map(data, function (x)
    {
        return {
         id: x.id,
         text: x.text
        };
    });
    $("#timezone").select2({
         data: result,
         placeholder: "Select timezone",
         escapeMarkup: function (markup)
         {
            return markup;
         }
       });

       $('#timezone').val(_timezone_id);
       $('#timezone').select2().trigger('change');

       // Have tried below, but no luck :(
       //$("#timezone").select2('data', { id: _timezone_id, text: _timezone_text });
       //$('#timezone').val(_timezone_id).trigger('change');
      });

can I change Svelte delimiter?

I am working on a big project that use Smarty template engine with AngularJs and we need to move out from AngularJs to Svelte. we face a bad problem that the delimiter of smarty is the same as Svelte and I had been searched for any solution to change delimiter of Svelte and I have been got nothing.
So, please I need to know if this possible to change Svelte delimiter or not?

Safe electron app that makes requests to another server web application

I want to create an electron app that supports sns features(upload videos, photos, basically share some info (nothing personal). I know that electron only has access to local addresses so I was thinking I could have another web server in between clients of the electron app and electron app, via node.js/express, make requests to the webserver. But would this be safe?

Toasty does not autoclose or manual close after hook list

I modified the code to generate a toast stack into a ToastContainer dynamically as a notification system. Now the toast do not autoclose even in close button click.

The code can be reproduced by copy and past inside of dimiss area in https://react-bootstrap.github.io/components/toasts/

const Tsty = (props) => 
    <>
    <Toast show={ props.show } delay={ 3000 } autohide>
      <Toast.Header>
        <img src="holder.js/20x20?text=%20" className="rounded me-2" alt="" />
        <strong className="me-auto">{props.title}</strong>
        <small className="text-muted">{props.time}</small>
      </Toast.Header>
      <Toast.Body>{props.body}</Toast.Body>
    </Toast>
    </>
render(<Tsty />);

function Example() {
  const [listNtfy, setNtfy] = useState([]);
  const style = { position: 'fixed', bottom: '60px', right: '10px', zIndex: '1000'}
  return (
    <>
    <Button onClick={() => {setNtfy([...listNtfy, {title: 'title #', time: 'now', body:  new Date().toString(), show : true }])}}>Add Ntfy</Button>
    <ToastContainer style={style}>
      { listNtfy.map( (x,i) => <Tsty show={ x.show } title={x.title + i} time={x.time} body={x.body} key={i} /> ) }
    </ToastContainer>
    </>
  );
}

render(<Example />);

where is the error?

The best way to implement override data state from parent class

I’m facing a really hard problem. I want to create a wrapper class that can do something like “override” the state of the child without affecting them. Quite hard to understand, I know.

Let’s see some minimal code below:

class State{
    key: string; //Unique key
    //This is really complex, nested, array, etc state.
    value: number | string | State | State[] | any
}

class Child{
    state : State;
}
class Wrapper{
    overrideState: State;
    child: Child;
    
    constructor(child: Child){
        this.child = child;
    }

    getFinalState() : State{
        //This will return the new State (or not), that is the final state
    }
}

A function to call them:

function client(){
    let child = new Child();
    child.state = new State();
    child.state.value = "original";

    let parent = new Wrapper(child);
    parent.overrideState = new State();
    parent.overrideState.value == "overrided"

    console.log(parent.getFinalState().value); //It should be `overrided`, simple
}

The problem is State class is really complex.

Actually, I have almost done with the getFinalState function by using looping, checking type, Lodash.cloneDeep,…a ton of code.
And I think it’s really complex to maintain, hard to read, and maybe has some risk.

I don’t think my way is right, I try to research some design patterns but am still stuck.
If you have any ideas, keywords, or something. I really appreciate that. Thank you

ES6 way to use filter and map to extract key value from JSON array [duplicate]

Consider there is JSON array

var arr = [
    {id: 123, name: Mike, age: 24}, 
    {id: 124, name: Bill, age: 36}, 
    {id: 125, name: Jack, age: 58}
];

The expected result is array of name based on given range of id, i.e. all names where age between 18 ~ 50

[Mike, Bill]

Here is what I think of extraction but I am not very keen on ES6 syntax, here is what I did

this.arr.filter(row => row.age>=18 && row.age<50).map( ???? )

and struggling on how to write the code within map..