« first day (4947 days earlier)   
04:00 - 17:0020:00 - 21:00

4:29 AM
hello guys
i just want to know the difference between bellow usage
function hello(thing) {
  "use strict"
  console.log(this.name + " says hello " + thing);
}

hello.call({name:"samitha"}, "world")


function hello2(obj, thing) {
  "use strict"
  console.log(obj.name + " says hello " + thing);
}

hello2({name:"samitha"}, "world")
i know first hello function handle with this context
So why we prefer hello instead of hello2
 
 
3 hours later…
7:41 AM
@underscore I don't think we do?
If you have a function that conceptually uses two parameters, you should be giving it two parameters, like hello2 works. The reason to use this is if you 1. have a method 2. it's actually important for using the data off the object it belongs to. You shouldn't be creating methods and only add instance data for that one method. Assuming the data doesn't belong there.
E.g., if you have some person object, it's expected to have, for example, name on the instance. But not timeOfDay. So, if there is a greet() method, it should take the name from this but accept timeOfDay as a parameter. Thus the implementation can be greet(timeOfDay) { return this.name + " says good " + timeOfDay;} and would be called as bob.greet("afternoon")
 
8:04 AM
this is the point Assuming the data doesn't belong there.
if we explicitly defined the first param as the object which is belongs to the function it's use some other use case
 
8:32 AM
@user7886229, short answer, use node-fetch@2.6.1
here's a working example
mkdir /work/node-fetch-test
cd /work/node-fetch-test
npm init -y
npm install node-fetch@2.6.1
npm install webpack webpack-cli --save-dev
  //index.mjs

        import fetch from 'node-fetch';

        var mode    = typeof window=='undefined' ? 'node.js' : 'browser';

        var url     = mode=='node.js' ? 'https://www.google.com' : 'test';
        var res     = await fetch(url);
        var txt     = await res.text();

        if(mode=='node.js'){
              console.log(txt);
        }else{
              document.body.append(txt);
        }
  //server.js

        require('http').createServer(request).listen(4000);

        function request(req,res){

              console.log(req.url,req.method);

              if(req.url=='/test'){
                    res.end('boy-meets-world');
                    return;
              }

              if(req.url=='/main.js'){
                    var fd    = require('fs').createReadStream('dist/main.js');
                    fd.pipe(res);
                    return;
              }

              res.writeHead(200,{'content-type':'text/html'});
npx webpack ./index.mjs
node index.mjs
node server.js
open browser at localhost:4000
i produced a dockerfile for some reason lol
# dockerfile

# docker build . -f dockerfile -t node-fetch-test
# docker run -d -p 4000:4000 -p 22:22 --name node-fetch-test node-fetch-test


FROM node:20

ENV NODE_VERSION 21.6.2

EXPOSE 4000


RUN apt update && apt install -y openssh-server
RUN mkdir /var/run/sshd

# Set root password for SSH access (change 'node' to your desired password)
RUN echo 'root:node' | chpasswd

RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22


RUN mkdir /work
WORKDIR /work/
but you can just delete the node-fetch-test directory to get rid of everything
if you use the latest version of note-fetch, it contains a lot of node:modules, i'll look into how to bundle those properly
sorry, the docker run command at the top of the dockerfile is wrong, stackoverflow wont let me edit it
it should be
docker run -i -p 4000:4000 -p 22:22 --name node-fetch-test node-fetch-test
notice the -i ( interactive ) rather than -d ( detach )
ive been pretty spooked trying to get multiple node processes to start
 
9:00 AM
helped me renew my webpack stuff a little :)
 
9:40 AM
i wrote a medium article about primitive immutability medium.com/p/ec64dc21bb80
 
10:22 AM
i just read it
 
this is quite good [micro:flowcharts] miro.com/app/board/uXjVKMqswso=
 
10:35 AM
Can't connect metro bundler in react native
 
@DeepaSuryawanshi Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
Can't connect metro bundler in react native Android "react-native": "0.72.1",
Is there anyone from react native, who can help
 
10:48 AM
@underscore Symbol and BigInt are also primitive types
 
posted on May 02, 2024 by Ben Mason

Hi everyone! We've just released Chrome Stable 124 (124.0.6367.111) for iOS; it'll become available on App Store in the next few hours. This release includes stability and performance improvements. You can see a full list of the changes in the Git log. If you find a new issue, please let us know by filing a bug. Erhu Akpobaro Google Chrome

 
 
3 hours later…
1:35 PM
@CommonMan What's to comment? You've accepted an answer lol
 
@matt thanks
 
@underscore Are all the typos to catch the plagiarism bots? 😂
 
What i noticed from people who are not understanding the immutable vs mutable is that they are just think var name = "something", string ( value ) will be assigned to the variable . Even with the obj, arrays or function ( which is mutable by default ) also think right part will be assigned to left
@matt also i have created a mind map for React miro.com/app/board/uXjVKNOzRK0=
Hi Guys, When creating a function with singleton design patten, is there any other way to optimised this code ?
const Config = (function() {
  "use strict";
  let instance;

  function init() {

    let config = {
      name: "samitha",
      age: 35
    }

    return {
      getConfig: function() {
        let freezedCopy = {}

        for (const key in config) {
          Object.defineProperty(freezedCopy, key, {
            value: config[key],
            configurable: false,
            writable: false,
            enumerable: false
          })
        }

        return freezedCopy
      },
      updateConfig: function(data) {
 
2:21 PM
@underscore, it depends what youre intending to do with it, can you give an example of how you intend to use it?
 
 
is there any usecase where instance can be null
if (!instance) {
        instance = init()
      }k
 
 
2 hours later…
4:42 PM
posted on May 02, 2024 by Ben Mason

Hi everyone! We've just released Chrome Beta 125 (125.0.6422.21) for iOS; it'll become available on App Store in the next few days. You can see a partial list of the changes in the Git log. If you find a new issue, please let us know by filing a bug. Krishna Govind Google Chrome

 
04:00 - 17:0020:00 - 21:00

« first day (4947 days earlier)