|
Rosalind posted:I am very, very new to using Javascript and sometimes have to write little snippets for my workplace. I am trying to have a function that reads something from the url and then uses it to pass along some info in a url when the participant clicks on a link. The code I wrote works on most modern web browsers but I just had someone testing the website out come back to me and say that on their iPhone 5 with Safari they got an error message. This is the code: In addition to the double declaration of city, I would guess that mobile safari might not support the "search" method you're using. Since search takes a regex, but you're not using any regex features, you can replace it with indexOf. Also, you probably want to compare citystart to -1 instead of 0, or use >=
|
# ? Oct 12, 2017 21:31 |
|
|
# ? Jun 5, 2024 19:51 |
|
Thanks for all the feedback. I made the suggested changes (removed the duplicate variable declaration, changed search to indexOf, changed the comparison to -1 instead of 0). Unfortunately she's still having the issue. Referrer definitely works on other iPhones including older models so I'm not sure that that's it.
|
# ? Oct 12, 2017 22:17 |
|
Rosalind posted:Thanks for all the feedback. I made the suggested changes (removed the duplicate variable declaration, changed search to indexOf, changed the comparison to -1 instead of 0). Unfortunately she's still having the issue. Referrer definitely works on other iPhones including older models so I'm not sure that that's it. Have you checked it on the same version of iOS/Safari on another phone? Wild guess but maybe she has some settings block or something that affects document.referrer? If I were in your shoes, I'd probably write out the values of each variable onto a dom element, then ask her to take a screenshot of what it prints out. Something like: code:
|
# ? Oct 12, 2017 23:02 |
|
https://www.htmlgoodies.com/beyond/webmaster/toolbox/article.php/3889011/Using-Safari-for-iPhone-iPad-and-iPod-Touch-Website-Testing.htm Ooh. Safari -> Preferences -> Advanced -> Show developer menu -> Right click -> User Agent -> Select any safari you want.
|
# ? Oct 13, 2017 02:30 |
|
Rosalind posted:Thanks for all the feedback. I made the suggested changes (removed the duplicate variable declaration, changed search to indexOf, changed the comparison to -1 instead of 0). Unfortunately she's still having the issue. Referrer definitely works on other iPhones including older models so I'm not sure that that's it. Huh, I distinctly remember having this problem because referrer wasn't passed. Then again, it was years ago, so maybe they added it since then.
|
# ? Oct 13, 2017 15:06 |
|
Lumpy posted:Huh, I distinctly remember having this problem because referrer wasn't passed. Then again, it was years ago, so maybe they added it since then. I remember using referrer to let customers pass options to our integration iframes five years ago and I'm pretty sure we tested it on iOS.
|
# ? Oct 13, 2017 15:12 |
|
Just to not leave people hanging I think I discovered the issue and it's not Javascript-related, or at least not related to any Javascript I wrote. Our person responsible for the website (not her main job) used Wix to make the site. It's apparently a known issue that Wix behaves oddly or even doesn't work entirely on older iPhones. We're going to explore migrating to some other site builder that promises backward compatibility although apparently Apple recently stopped providing support for iPhone 5 series phones. Anyways, thank you all for your help!
|
# ? Oct 13, 2017 19:16 |
|
Rosalind posted:iPhone 5 quote:Available: September 21, 2012 I think when official support ends, so should yours.
|
# ? Oct 13, 2017 21:03 |
|
Ranzear posted:Tell them they bought an Apple device, they were supposed to throw it away for the new one years ago. I work in health research and we need to be able to accommodate participants who might have older phones unfortunately otherwise I'd wholeheartedly agree!
|
# ? Oct 13, 2017 21:20 |
|
Yeah that's fair. I used to redirect IE users to the Chrome download page when they didn't have Canvas and IE6 users to that 'IE6 is dead, please move on' page.
Ranzear fucked around with this message at 23:44 on Oct 13, 2017 |
# ? Oct 13, 2017 23:41 |
|
Crossposting from the horrors thread because maybe it's not a horror?dev bootcamp instructor posted:
This is how I'm being taught to do promises, and I feel like it's unnecessary because ajax already returns a promise so you're just unnecessarily wrapping a promise in another one with no data transformation happening. Is there some benefit to this?
|
# ? Oct 19, 2017 04:21 |
|
It would be far better demonstrated if the JQuery was ditched for XMLHttpRequest or fetch. I'm not sure if JQuery's Ajax function actually return a compliant promise because I haven't used it for so long, but yes, using promises without transformation is meaningless obfuscation. The purpose of promises is two fold, as a writer of promise return code, its providing a consistent API for async code that can be arranged in all sorts of manner, as a consumer of promise code, it's being able to work with the results of that asynchronous computation like they were values, so you can perform maps, transformations, etc without having to think too hard about the asynchronous bit. The example above a shows the API with none of the why.
|
# ? Oct 19, 2017 04:36 |
|
Rosalind posted:I work in health research and we need to be able to accommodate participants who might have older phones unfortunately otherwise I'd wholeheartedly agree! I have to support state and county level government computers, weep for my minimum specs. On the plus side, I did convince sales that new contracts starting in 2018 have to use "modern" browsers as defined by Microsoft (Edge, not IE). How well that'll work, we'll see, but at least I can tell them "I told you so". And then go add backwards support. Ironically we did have one state that delayed deployment because, while we worked in the latest browsers, a sister software install didn't and would need some time to resolve the issues.
|
# ? Oct 19, 2017 04:37 |
|
Maluco Marinero posted:It would be far better demonstrated if the JQuery was ditched for XMLHttpRequest or fetch. I'm not sure if JQuery's Ajax function actually return a compliant promise because I haven't used it for so long, but yes, using promises without transformation is meaningless obfuscation. The purpose of promises is two fold, as a writer of promise return code, its providing a consistent API for async code that can be arranged in all sorts of manner, as a consumer of promise code, it's being able to work with the results of that asynchronous computation like they were values, so you can perform maps, transformations, etc without having to think too hard about the asynchronous bit. I'm almost positive that jQuery 3's big thing was ditching their wrap around code and just using native promises and such. The rest, yes.
|
# ? Oct 19, 2017 04:39 |
|
Dross posted:Crossposting from the horrors thread because maybe it's not a horror? jQuery's Ajax is not a "real" promise, so if you need an actual Promise conforming solution, you'd so something sort of along those lines. But that is a very odd way of trying to teach someone promises. In fact, it may be the worst way I could think of. Tomorrow, I will post links I have bookmarked about promises that I found helpful when I'm at a computer. They aren't really that complicated, but there are a few gotchas. FYI, the "modern" way to do that example is with the native fetch API, which does actually return a real promise: JavaScript code:
|
# ? Oct 19, 2017 04:40 |
|
ajax can chain .then and .catch off of it like a real promise (in addition to the original .done and .fail), and be included in a promise.all array. What other differences would there be to look out for? I've only been doing JS for about two months but I think I have a pretty good grasp on how to think in terms of data transformations as opposed to imperatively. Which makes me chafe at the fact that we're being taught imperatively. I study in my free time too so sometimes we'll be getting taught something and I'm thinking "I already know a much better way to do this" which is probably Coding Newbie Trap Alpha. edit: I think jQuery 3.0 made deferred objects fully compatible with the ES6 native promise API unless I'm misreading/misunderstanding something. Dross fucked around with this message at 05:20 on Oct 19, 2017 |
# ? Oct 19, 2017 05:13 |
|
Dross posted:ajax can chain .then and .catch off of it like a real promise (in addition to the original .done and .fail), and be included in a promise.all array. What other differences would there be to look out for? I haven’t used jQuery in a long time, so it is quite possible that it is actually using Promises now. I’ve been doing JS for almost as long as it has existed so sometimes my knowledge is from what I remember from using something 10+ years ago....
|
# ? Oct 19, 2017 17:28 |
|
Let's be clear to at least two people now in the past week or so: You're being taught JQuery, not Javascript.
|
# ? Oct 19, 2017 18:21 |
|
I was taught vanilla JavaScript before we incorporated Jquery. They just held off on teaching us promises until we could use them in a really stupid way I guess
|
# ? Oct 20, 2017 00:38 |
|
Shot in the dark but... My npm start script: code:
code:
|
# ? Oct 24, 2017 21:24 |
|
huhu posted:Shot in the dark but... Can you try the verbose flag to maybe get more info? Shell session code:
|
# ? Oct 24, 2017 22:12 |
|
huhu posted:when run in Pycharm in debug mode results in It's been a long time since I worked through Pycharm like this so I can't exactly help you, but I long ago moved to just running my dev server in a separate terminal. Just works nicer.
|
# ? Oct 24, 2017 22:52 |
|
Thermopyle posted:It's been a long time since I worked through Pycharm like this so I can't exactly help you, but I long ago moved to just running my dev server in a separate terminal. Just works nicer. The only time I'd consider running in IntelliJ derived IDEs is when debugging.
|
# ? Oct 25, 2017 08:13 |
|
Dogcow posted:Can you try the verbose flag to maybe get more info? code:
|
# ? Oct 25, 2017 14:56 |
|
Speaking of debugging with Jetbrains IDEs... You can now use the browser <> IDE Javascript debugging with Chrome while DevTools is open. This is big news! https://developers.google.com/web/updates/2017/10/devtools-release-notes#multi-client In case you aren't aware of what I'm talking about you can set breakpoints in your code in your IDE, and when the browser hits those breakpoints it breaks in your IDE where you can inspect variables and all the other stuff you do while debugging.
|
# ? Oct 25, 2017 15:05 |
|
huhu posted:
You don't have quiet or noInfo set to true in your webpack config do you?
|
# ? Oct 25, 2017 17:15 |
|
I hate for loops. I think for the most part a for loop is better replaced by something more modern, .forEach, .some etc. However I have a for loop that tries to find the first element match and then returns out of the function. Trying to do the same with a for each is impossible because returning in a foreach just causes the foreach to begin parsing the next element, it doesn't return at the higher scope. Is there a better way to do this other than using a for loop?
|
# ? Oct 25, 2017 18:16 |
|
Knifegrab posted:I hate for loops. I think for the most part a for loop is better replaced by something more modern, .forEach, .some etc. If you are using TypeScript, you can use the ES6 for...of loop in ES5. If you are using ES6... use for...of. There are also things like lodash.find, which does exactly what you want.
|
# ? Oct 25, 2017 18:19 |
|
Skandranon posted:If you are using TypeScript, you can use the ES6 for...of loop in ES5. If you are using ES6... use for...of. Unfortunately I cannot use find or for of because I am comparing each element in two different arrays, so of would only give me the element of one array. Similar reasons for find, since find would only return the found element (that is different) but cannot tell me how they differ. For in also would not work because it does not respect order (it iterates based on when the particular key was added not the value of the key).
|
# ? Oct 25, 2017 18:22 |
|
Knifegrab posted:I hate for loops. I think for the most part a for loop is better replaced by something more modern, .forEach, .some etc. JavaScript code:
EDIT: you can also use .find() to return the first match in an array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find EDIT2: Oh you said you can't use find... Lumpy fucked around with this message at 18:30 on Oct 25, 2017 |
# ? Oct 25, 2017 18:23 |
|
Knifegrab posted:Unfortunately I cannot use find or for of because I am comparing each element in two different arrays, so of would only give me the element of one array. Similar reasons for find, since find would only return the found element (that is different) but cannot tell me how they differ. I don't see how for..of can't work where you imagine forEach would, but if not, no, there are no other options. Edit: Yeah, do the above thing, that's a great idea.
|
# ? Oct 25, 2017 18:24 |
|
My assumption going into this was that a standard for loop is my best bet, I was just curious if there was some other means I wasn't seeing. I don't like for loops, for reasons I can't articulate but I am fine with it, I would prefer to do it right than hacky and yeah I knew about the throw approach *barfs intensly* .
|
# ? Oct 25, 2017 18:30 |
|
Knifegrab posted:My assumption going into this was that a standard for loop is my best bet, I was just curious if there was some other means I wasn't seeing. I don't like for loops, for reasons I can't articulate but I am fine with it, I would prefer to do it right than hacky and yeah I knew about the throw approach *barfs intensly* . I suspect that there is some XY Problem here. Can you share a bit more code to see if there is a better way to approaching the end goal?
|
# ? Oct 25, 2017 18:32 |
|
Lumpy posted:I suspect that there is some XY Problem here. Can you share a bit more code to see if there is a better way to approaching the end goal? Sure, its just a really really simple bit of code to help sort IP addresses. code:
|
# ? Oct 25, 2017 18:40 |
|
JavaScript code:
e: oh, yeah, that'd be more annoying Might be more performant to map them to eg {padded: '004.004.004.008', original: '4.4.4.8'}, sort them based on simple string comparison and then map them back to the original value. Munkeymon fucked around with this message at 18:46 on Oct 25, 2017 |
# ? Oct 25, 2017 18:41 |
|
Knifegrab posted:My assumption going into this was that a standard for loop is my best bet, I was just curious if there was some other means I wasn't seeing. I don't like for loops, for reasons I can't articulate but I am fine with it, I would prefer to do it right than hacky and yeah I knew about the throw approach *barfs intensly* .
|
# ? Oct 25, 2017 18:46 |
|
Gross, mutating the array while iterating it. In other news, turns out embedding React into an Ember app is super easy. This excites me.
|
# ? Oct 25, 2017 20:25 |
|
necrotic posted:Gross, mutating the array while iterating it. Since the array is never passed anywhere or returned in anyway I think its cool and good.
|
# ? Oct 25, 2017 20:40 |
|
At least stop shadowing the arguments. You'll drive me mad! Maybe that's the goal?
|
# ? Oct 25, 2017 21:21 |
|
|
# ? Jun 5, 2024 19:51 |
|
Knifegrab posted:Since the array is never passed anywhere or returned in anyway I think its cool and good. If you're going to mutate, why not go nuts!: JavaScript code:
|
# ? Oct 25, 2017 21:43 |