« first day (1993 days earlier)      last day (2953 days later) » 

10:00 PM
doesn't work on multilines
and no, there isn't a better way
 
it worked before, just like this
oh I got it
 
works here
doesn't `work`
here
 

Sandbox

Where you can play with regular chat features (except flagging...
@AlexGray there is a room specifically for testing the chat
feel more than welcome to spam in there testing stuff
no one will care (in there)
 
var power = function(base, exponent) {
var result = 1;
for (var count = 0; count < exponent; count++)
result *= base;
return result;
};

how does this function know that result should equal the value of the exponent and not 1? I understand that the loop counts up and stops at the value of exponent, but then does it assign that value to result?
 
because you can omit the {} for the next statement
for( ... ) {
  result *= base;
}
return result;
is what is happening
but it is harder to read, so always use {} :P
 
10:11 PM
so if there were brackets there its assigning the final value of the count to result? And multiplying it by base?
im just confused because if result is defined as "1" how does it know in the statement result *= base that 'result' should equal exponent based off the loop? Does the loop asign it's final value to result?
 
because you're multiplying by base exponent number of times
 
@SterlingArcher youtube.com/watch?v=rqMrZlLJXRA hahaha :D
 
@GNi33 SterlingArcher is afk: drinking away the serial port pains
 
i know I'm wrong but how my brain is understanding now that last statement says that

result = result * base

And if we defined result earlier as "1" wouldn't that just be the same as base * 1? how does it know that "result" is supposed to equal the exponent
and NOT 1 as we defined earlier
 
what do you mean " how does it know that "result" is supposed to equal the exponent"
 
10:15 PM
to me it looks like result = 1
but the squaring is done by result *= base. So how does it know that result is supposed to equal the exponent not 1 as we previously defined it
 
does it have to do with the 'return' part?
 
nothing equals the exponent
you're using the exponent to count how many times you multply the result by itself.
 
...Tim Cook just responded to my startup's email 0.0
 
Hello friends, how do I add a reference to another link in javascript?
 
10:19 PM
idk i guess im just stupid. Because to me it seems like it would just multiply by 1 over and over
 
why
it's multiplying 1 by base
base is whatever you pass it
then result is now the result of base * 1 (in my example 2) which is 2
so the next time in the loop you get 2 * 2
then the next time 2 * 4
and so on..
 
yeah idk lol i give up trying to understand why it works because riight now I cant
i dont wanna waste any more time with the stupidity
 
I can tell I'm now going to waste an hour on Reddit instead of writing my essay
 
10:22 PM
this is the loop broken out
 
Thanks Madara
 
(my example again)
 
oh shit
ok
it's because of how JS works. Every time you 'redfine' a variable within the scope, it just holds that value
 
well you're saying foo = foo + 1; which redefines foo as itself + 1
so you are redefining it
but with the value of itself (in the equation)
 
it's originally one, but after the first loop it's 2. It's still two when you do it again, it doesn't go back to 1 just because we said it was one when we started
 
10:24 PM
yea, because you're over writing it
 
gotcha and thats just how javascript works I don't need to understand much further than that i hope
 
var foo = "foo";
foo = "apples";
console.log( foo ); // what would you expect?
 
apples
 
okay, so that is also what is happening in the loop
 
gotcha, thanks dude
 
10:25 PM
!!> 12["toString"]["length"]
 
@MadaraUchiha 1
 
Without looking in the console/docs, why 1? :P
 
I want apples now
foo
 
@MadaraUchiha because 12.['toString'] ??
!!> 12..toString()
 
10:26 PM
@rlemon "12"
 
@rlemon Why is the result of my expression 1?
 
Does Caprica Six eval JS?
 
@MadaraUchiha not sure, but it would be trying to call toString on something I don't know what it would be getting
because you're missing the .
 
@TristanWiley she can but i'd do it in the sandbox I think
 
Gotcha
 
10:27 PM
@TristanWiley eval is in a webworker
no document, no window, no other stuff
 
@rlemon 12["toString"] is the function Number.prototype.toString, and Number.prototype.toString accepts one argument, therefore has a length of 1 (radix)
 
ah, makes sense.
in a js kinda way
I suppose
 
Saw that question on a particularly nasty interview quiz
 
I'd be impressed if a candidate knew something about why 12.toString() doesn't work
because I always thought that was pretty edge case knowledge for most
 
Also had a really nasty one about ASI
const a=(a,b)=>a+b
const b=a
(5,6) + (7 == 7)
What's b?
 
10:33 PM
b is the beef I have with whoever didn't fucking use semicolons
 
@MadaraUchiha 12?
 
Intuitively, b would be === to a, but ASI doesn't work with a newline between the function name and the parameters in a call.
So the answer would be 12, because a(5,6) === 11 and you add +true to it.
 
/me wants a cookie
 
That was in an interview?
 
wtf lol
 
10:35 PM
> Will I encounter code in your code base that looks like this?
> Ok well thank you for your time.
 
i'll just assume it's ok that's all WAY over my head
 
@Loktar I really would be first and foremost questioning the quality of their codebase if that is in the interview
 
lol yea
 
I don't have time to be answering code golf questions in a js interview
 
I seriously would ask that, no shame at all.
exactly
Those are the kinds of questions just meant to make people feel superior imo.
they are fun in this environment don't get me wrong
but in an interview that's out of place
 
10:37 PM
the trick questions I can understand are the ones that still almost follow convention
like
return
{
blah
}
probably works in a lot of languages that share syntax with js
 
@Loktar That was in a suggested interview that was designed to be PARTICULARLY nasty, by one of the best JS devs in our company
(He's at least Benji level)
 
@MadaraUchiha what kind of candidates are you vetting?
 
that looks like that would work if it were in a function
 
@Loktar A theoretical one
 
lol
 
10:38 PM
@corvid it would, but ASI puts a ; on the line ending after the return
 
@corvid It would not.
 
so you get
return ;
{

}
@MadaraUchiha it would
function()
{

}
 
@MadaraUchiha in es6, if blah were a variable that were a string? It would return { blah: blah }, no?
 
@corvid No
 
ohh sorry I misunderstood
 
10:39 PM
Because ASI will put the ; right after the return.
 
@corvid the problem is ASI
51 secs ago, by rlemon
return ;
{

}
is how it gets translated
 
Not only that, but { blah } isn't interpreted as an object in this case
It's interpreted as a block
With a single expression inside (blah)
 
But that would change if you just put the { on the same line as return.
 
The correct form is only
return {
  blah
};
 
can ASI be turned off? in strict mode?
 
10:40 PM
The "same line" guideline is mandatory.
 
not to my knowledge
return { blah }; is ofc also acceptable
 
Yea, I never have the problem, but it'd be nice to be able to opt out of ASI.
 
point is { must be on the same line
 
@Luggage Yes
But putting goddamn semicolons wherever they need to be and not being lazy about it :D
You can have ESLint fail your build when you're missing semicolons, getting the same effect.
Which is what I do.
 
Also, use an editor with the ability to have an eslint plugin so it's clear when it's wrong.
I started with it in my build, but I found it more useful in the editor
Both is ideal... but..
 
10:43 PM
@Luggage but... what?
 
ideal is having a git hook too
 
but I like to trail off...
 
I put it in our build, if you want an editor plugin, install one
You're a competent developer, you can do it, I trust you
 
yea, as a group decision build makes sense.
 
@Luggage I pretty much made the call by myself on that one :D
I just let the others know I did it as a complete and sealed fact.
 
10:44 PM
A decision FOR a group, i mean.
 
"Going forward, we have ESLint running on our code, and it will hurt your feelings a lot."
 
@MadaraUchiha ", for about a week, then you'll just write better code."
 
ESLint would poop itself if I showed it this code I inherited.
 
@Luggage I pretty much singlehandedly fixed about 500 issues to get ESLint running without explosive diarrhea.
The --fix option didn't do much good for me.
 
@MadaraUchiha you're a bad person.
 
10:52 PM
hah glad I have 10k
otherwise you miss gems like that
 
Don't know what you're talking about.
 
I would be tempted to make a stupid answer on a question like that. Probably get myself in trouble
 
son of a bitch. It's thursday, here!
ohh right. I gotta stay off the internet tomorrow
so I don't end up in the real news.
 
guys
My company heavily relies on jQuery for its frontend
 
Don't they all :(
 
11:01 PM
and it's a fast growing company and we always want to add new features inspired by other sites and shits
 
That's not a question. More like a plea for help. :)
 
but all those inpirations come from sites built in AngularJS
 
AngularJS is the new jQuery
 
I want to start migrating some code into AngularJS to give it some structure to the frontend code
 
Want a few divs -> use ng-repeat!
130k of framework code
 
11:03 PM
any suggestions on procedures? Luckily I've been keeping in somewhat modular so we have blog,homepage,proposals, portfolio etc completely separately
 
@Oleg as in it's a powerful tool that people use stupidly?
 
so I can basically migrate code module by module
 
Would you say that your app is well organized or a loose collections of pages, each difference?
 
@Oleg I'd just use components
 
@phenomnomnominal as in a big tool that people use stupidly
 
11:04 PM
@Luggage for example Blog uses completely separate copy of Drupal
 
@EnglishMaster there are no components in angular
 
hosted on different instance of EC2
@Oleg I'm going to use Angular 2
 
angularjs 2 is still 120K minified
and then you need to add things
like the router
 
I straight away suggested Angular 2 when I figured out it support universal rendering
only reason why we didn't prefer Angular was it doesn't support SEO
 
hey, im trying to do a onclick in my page.. this is the code : ```onclick="LoadContent({roomId: '<?php echo $RoomData['id']; ?>', hour: '<?php echo $i; ?>', minute: '<?php echo $minute; ?>', viewtype: ''}, '/ajax')"```

the function: ```function LoadContent(params, url){
var TitleURI, ContentURI;
TitleURI = url + '?view=title&' . $.param(params);
ContentURI = url + '?' . $.param(params);
$('#AjaxModalTitle').load(TitleURI);
$('#AjaxModalContent').load(ContentURI);
$('#AjaxModal').modal(toggle);
 
11:06 PM
@KristianHareland Welcome to the JavaScript chat! Please review the room rules. Pleasedon't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
 
@Oleg That is pretty much nothing (120k)
 
@Oleg yes there are
 
@KristianHareland What is this dark magic TitleURI = url + '?view=title&' . $.param(params);
 
We probably spend 70% of bandwidth on Images
and videos
and normally those main script (jQuery or Angular) gets cached on first load
(cached on clients side)
 
@phenomnomnominal I'm not talking about the component method.
 
11:09 PM
@Oleg seems like you have a problem with stupid people, not with angular
 
I wouldn't mind if Angular was 1MB minified in total
@phenomnomnominal who's stupid peopl?
 
@EnglishMaster I hope I never use any of your websites
 
@Oleg why?
 
@phenomnomnominal First of all I have a problem with myself, then with stupid people.
 
11:10 PM
@EnglishMaster 1MB on mobile? Good luck.
 
I have a problem with authority.
 
I got 99 problems..
 
@Oleg I think most of the website would have 1 ~ 2 MB scripts and css files if you sum up everything you have
 
basically from line 97
 
@EnglishMaster I mean that's just not true
 
11:12 PM
but it's normally fine because all of them gets cached on first load
 
that would fall under the "using it stupidly" banner
 
even this chat is only like a half meg on a hard reload
 
Wasn't it Google who said: "make it under 60K!"
 
@Oleg hard to do with image rich content :/
script size, doable tho
 
@Oleg : im trying to do the same as php do with http_build_query(array('param_1' => 'foo', 'param_2' => 'bar'
 
11:13 PM
@rlemon virtual-dom + redux is less than 30K
 
is that images?
lol
I wasn't disagreeing with you on script size.
 
Images are a problem, yeah...
 
@Oleg I worked on a pretty big shopping mall built in Magento they have about 200,000 images
 
not all at once I hope
and if so.. ohh god no
 
we had to remove S3 from the server architecture
because it is faster to just host images (reference) from own server instead of doing round-trip to S3 for image reference
just for performance
 
11:17 PM
faster for your QA, or your customers
 
that site has images for their products with around 800kb to 2mb in filesize
customers
 
How would i convert an array into url params? preferrably the same way you do with php: ´´´http_build_query(array('param_1' => 'foo', 'param_2' => 'bar'))´´´
 
that ended up giving much more bandwidth burden on the server
but worth it because of performance
 
@KristianHareland you mean an object?
arrays in js don't function the same as with php
you can't have string keys
 
@rlemon im not that good at javascript tbh. I mean when i use: foo({param:'foo', param_2:'bar'});
 
11:20 PM
yes, that is an object
{foo} object
[bar] array
 
alright, duly notesd
 
in a nutshell
so you want Object.keys(object) to explode the keys to an array.
Object.keys(obj).forEach(function(key) {
  console.log( key, obj[key] );
});
 
anyways, im trying to pass this into a function, but i want it to change to the same way you do with php 's function hhtp_build_query();
 
is a very good start
 
Usually if you want to iterate over an object's keys/values, you want a map
 
11:22 PM
ei: onclick="function({item:'123', type:'product'})"
 
@KristianHareland Are you trying to do redirection?
 
If you're ok with using javascript maps
 
not really, open a ajax loaded modal
 
@Meredith how do you extract key values with map?
ohh a Map? or .map?
 
Map.forEach((key, value) => ...)
 
11:23 PM
k. I thought you meant .map at first
I was very confused
 
why not use Rest API and post that data in your body of request instaed of turning it into string param?
 
you're building a querystring? like "?key1=value1&key2=value2"?
 
Also it's (value, key) oops
 
and are you using npm or bower? (if so I'll suggest using a package that does it for you)
OR if you want to just write it..
 
11:25 PM
give a man a fish
 
I'm pretty sure I could write a novel about how shitty javascript maps are
 
Map.forEach and my suggestion are both like 90% of the code
 
I'm giving no fishes.
 
Object.keys(params).reduce(function (query, key) {
   return query + key + '=' params[key];
}, '?');
Something like this?
 
im just using jquery inside a php file tbh...
im a real noob on js
 
11:25 PM
I'm figuring out if i want to suggest a package, a smooth looking es6 style or es5 shut
 
if you are using jQuery pass the object as is
jQuery will serialize it
data: obj
 
yea, is this $.ajax()?
 
var params = {id:'1', item:'111'};
ContentURI = url + $.param(params);
 
if he's using jQuery and not .ajax :P
 
Is typeof global === 'undefined' ? window : global safe to determine the current global context?
 
11:33 PM
figured out where my error was... undefined var, didnt show in console so was wierd..
 
11:46 PM
Hi guys
How can I escape the newValue for String replace function, see:
"str".replace("str", "-$'-");
this will return --
I want to escape the last parameter to be replaced literal without evaluating dollar sign or any characters ?
 
@AhmedSabry Do you mean "str".replace("str", "-$$'-"); ?
 
Good but "-$'-" would be get from a variable and is there is any more chars should I replace them before pass them to the replace function ?
 

« first day (1993 days earlier)      last day (2953 days later) »