Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

General JavaScript

Featured Replies

So, you see every n items should be wrapped in a row. For example wrap 4 items on desktops, 3 on tablets, 2 on smaller breakpoints and 1 on mobiles.

 

On top of that, the number of items should be a variable, if I need to call the function and pass different arguments, depending on how many items I have / need in a row.

Edited by teodora

  • Replies 422
  • Views 70.5k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • As soon as I saw the JS videos with that Mattias guy, I knew who he was straight away. He posts some really useful answers on Quora. I'd advise signing up if you haven't already. I've wasted hours re

  • Console.table, ladies and gentleman http://jsfiddle.net/juu5fx82/.   You need to use the JS console obviously, and hit 'run'. I never knew this existed.

  • jQuery's modular, you can build a custom version via Grunt, its pretty simple.   Before v3.0, which now uses requestAnimationFrame and Promises/A+, I'd use a build without Effects and Ajax with Velo

James and Robert, thank you very much for your help so far :) I realised what I am doing is not ideal, because I have to move the for loop within window.resize() if I want to get the updated variable when the window resizes. This generates a wrapping container every time the window resizes, which is far from ideal. Unwrapping the items and then wrapping them produces weird results, so I have thought of a different way of doing this.

 

But thanks a lot, your help is always much appreciated :)

  • Author

React Conf videos are slowly being added https://www.youtube.com/user/FacebookDevelopers/videos. I caught a bit of the live stream over the week and it was a good one this year. Highlights are Ben Alpert's talk and the rich text editing video.

The more and more I use React the more I feel Angular, the whole thought behind it is flawed. I hope I never have to use Angular or Angular 2 again.

 

React + redux are both amazing, when really all you care about on a front-end is the UI and it's state. These two handle that perfectly in a much less convoluted way than we are used to.

 

Forget the MEAN stack (Mongo, Express, Angular, Node) it's all about the MERN stack (Mongo, Express, React, Node) :)

As straightforward as JavaScript makes async, promises take a bit to get your head around - as things get messy when you have nested callbacks everywhere!

I'm not sure how you'd even do Async in PHP? It's possible in JavaScript because of closure, I have no idea how you'd make it work without!?!

 

If you wanna dig deeper into Async JS watch at least the intro (20mins or so) of the RxJS course on FEM, that looks like something really special...

Edited by rbrtsmith

 

Have you cracked it now?

 

I did! I wrote a function that I am too embarrassed to post here, though :D But it works and deadlines are met.

 

Sorry T I had totally forgotten about this!

 

No worries :D

I have a question (or two) that is more browser/device related than an actual JS question. But I guess its OK to ask here anyway.

I'm wondering what you all do to detect touch devices. I've read that the standard method (used by Modernizr) by checking if a global ontouchstart event returns true is not 100% reliable because several chrome and FF versions returns true in Windows (8 and 10). Also some devices might both have mouse inputs and touch screens.

To support such devices would you simply listen for both?

mySlider.addEventListener('mousemove', myHandlerFunction, false);
mySlider.addEventListener('touchmove', myHandlerFunction, false);

 

I have a question (or two) that is more browser/device related than an actual JS question. But I guess its OK to ask here anyway.

I'm wondering what you all do to detect touch devices. I've read that the standard method (used by Modernizr) by checking if a global ontouchstart event returns true is not 100% reliable because several chrome and FF versions returns true in Windows (8 and 10). Also some devices might both have mouse inputs and touch screens.

To support such devices would you simply listen for both?

mySlider.addEventListener('mousemove', myHandlerFunction, false);
mySlider.addEventListener('touchmove', myHandlerFunction, false);

 

Unfortunately there isn't a standardized 100% reliable way to detect touch devices, like modernizr works: it's generally better to do feature detection instead.

But yeah the code above should be fine. But you might wanna look into feature testing to avoid unneeded event handlers being added.

Edited by rbrtsmith

  • 2 weeks later...
  • Author

This is a really good talk that goes through the benefits of pure functions and minimising state. Games are often highly complex and deal with a lot of state at any given time, there's plenty to take away when it comes to building web apps.

 

This is a really good talk that goes through the benefits of pure functions and minimising state. Games are often highly complex and deal with a lot of state at any given time, there's plenty to take away when it comes to building web apps.

 

 

On the same subject Kyle Simpson has released a course of FEM covering functional programming basics, I think it's a fantastic introduction.

 

Covering topics like immutability, composable functions, pure functions that avoid side effects. I am really convinced that this approach scales far better than the traditional OO approach (At least with JavaScript)

  • Author

 

On the same subject Kyle Simpson has released a course of FEM covering functional programming basics, I think it's a fantastic introduction.

 

Covering topics like immutability, composable functions, pure functions that avoid side effects. I am really convinced that this approach scales far better than the traditional OO approach (At least with JavaScript)

 

I saw that. There're some interesting courses coming up this year https://frontendmasters.com/workshops. Especially around computer science, algorithms, data etc.

 

I'm still getting my head around a lot of this. I've signed up for a Redux & React course, and state is a big part of both of those. I have a few things to brush up on first though.

 

I saw that. There're some interesting courses coming up this year https://frontendmasters.com/workshops. Especially around computer science, algorithms, data etc.

 

I'm still getting my head around a lot of this. I've signed up for a Redux & React course, and state is a big part of both of those. I have a few things to brush up on first though.

 

Indeed, being self taught I have missed out a bit of some core computer science fundamentals so that course is a very welcome addition.

 

I've been doing the React and Redux courses on egghead.io. They're very good. Redux seems like a superb idea, although so far all the react projects I've played with I just hold state in a similar fashion - a single object on the root component and pass it down as props. The thing I like most about redux though is that it enforces immutability.

The testing courses are good as well. I am trying to make unit testing something I do all the time, although it takes time - bad habits die hard, but at least React makes automated testing of UI components much less of a nightmare.

Edited by rbrtsmith

  • 2 weeks later...

A quick question - I wonder how would you approach detecting form autocomplete event? For example on any input focus (or on change more likely), detect if the rest of the form inputs have been "autocompleted" :D

Edited by teodora

On an input focus or blur event you could loop through all the required form elements and determine the length of the strings entered, if any are still zero then the form isn't complete. Not sure this is exactly what you're looking for, I'd normally run this kind of validation on a form submission, or on the blur event of an individual field- and check only the one that has just been blurred.

I was thinking of something like this, on change check the val length of the other inputs - have to try it and see if it works.

I actually don't need to detect the autocomplete event per se, neither I need it for validation. I have labels acting as placeholders, moving on top of the inputs on focus - if there are any autocomplete values, the labels overlap.

  • Author

React Native for OSX https://github.com/ptmt/react-native-desktop.

 

My suggestion for a JS Air podcast is on tonight. Vue JS, with the creator, and Taylor (creator of Laravel) http://javascriptair.com/episodes/2016-03-30/. It really is an amazing framework. This is one of the podcasts I actually view every week.

  • 2 weeks later...
  • Author

Ok, one more.

 

Hactar is an insanely cool project that Kyle Simpson mentioned on JS Air, it detects JS features and libraries and installs the dependencies, build tools, imports etc that are required to run. Here's an example.

 

https://www.dropbox.com/s/7lwd3efcqh4scl4/Hactar-Screencast.mp4

  • 2 weeks later...

I've mentioned a few times on here that I very rarely use prototypes In JavaScript, and never use the ES6 'class' keyword as that is just syntax sugar for the 'new' keyword which is an abstraction to make prototypal inheritance look like classical inheritance for devs from other class-based languages who wish not to learn JavaScript properly - Unfortunately many tutorials teach this way of doing inheritance rather than the preferred Object.create() which was added to the language by Doug Crockford to circumvent the constructor/new nastiness.

 

Anyway I came across this post by Mattias Johansson (Senior Spotify Dev) that summarises these thoughts very eloquently:

 

I use them for parts of my apps that need extra high performance. Otherwise, I avoid them. Other than extreme circumstances where you are willing to sacrifice lots of dev time to squeeze every bit of performance out of JavaScript, the complexity that prototypes add will make your app worse off.
Generally, I think that prototypes are often used out of habit rather than need, because people come from strongly typed languages where you have to use a class for everything. In most cases, you are well off using simple object literals and functions that create them (sometimes referred to a factory functions). It is simpler and flexible.
I use prototypes when I need very, very high performance. An example of this might be if you're doing a virtual scroll component, where you need to create hundreds or thousands of objects in 1/60th of a second to achieve 60FPS. It won't help a lot, object literals are created extremely fast too (my iPhone can create hundreds of millions per second), so you won't gain a lot.
Sidenote 1: If you make use of bind, like most people do when using prototypes, you lose much of performance benefits of the prototype. This is not commonly known.
Sidenote 2: Keep in mind that the new keyword and the ES6 class keyword are just leaky abstractions on top of the prototype, that in my opinion complicates prototypes even further - they are tricky enough without convoluted abstractions on top of them. Not a fan.
In summary: Use prototypes for parts of your app that need insane performance, and avoid for other parts.

 

 

Edited by rbrtsmith

  • 3 weeks later...

Very cool

 

 

I've not got time to watch this video right now, but isn't JSPM just another version of Bower - which itself isn't much use as we can just use NPM to pull down modules which are easily required using ES6 modules...

  • Author

It basically works like require in Node, accept it can use files from NPM, Github as well as Common JS and Require JS Modules all on the client. I'm not sure if it uses Bower, but it doesn't look like it, everything in the demos is referencing NPM direct.

 

The beauty is that, just like node, there's no config process. If you want to use React and JSX, you simply require them and you can start using them straight away. You can also create static builds not just for all the code, but split depending on where the code is used like Webpack. You can also use other static files as modules like CSS and HTML, like Webpack.

 

I can't say I've used it before. I saw this video retweeted by Dan Abramov, but I thought it was an interesting approach to module loading. I see the value of Webpack but I honestly hate using it, like a lot. I think things like JSPM are great for workflow, and when you just want to hack away at a side project, or an idea, without the overhead of configuring everything.

 

I'd watch the video, it's impressive, even to watch someone code like that.

If Dan Abromov has recommended it then it's well worth investigating, he's a bit of a rockstar in the JS world! I shall try to find the time to check it out and report back my thoughts. Thanks for sharing :)

  • 1 month later...
  • Author

@@citypaul @@rbrtsmith I'm working on a pretty small app at the moment, and it would be a good project to start learning TDD, what are some good resources for learning it?

  • Author

If you are building it in React then there's a good course on egghead for testing UI using React Test Utils

https://egghead.io/courses/react-testing-cookbook

 

Also a gentle introduction that helped me was https://build-podcast.com/mocha/

 

Awesome, thanks. What test frameworks would you recommend? There're loads out there.

 

Awesome, thanks. What test frameworks would you recommend? There're loads out there.

 

There's a lot I haven't used. We've been using Jest in work, but I don't really like it. Mocha looks good. BBC use Jasmine. One I quite like is tape because it's so minimal. I think what it comes down to is finding the right testing suite for the job at hand.

 

Paul will expand on this but there are a number of different kinds of tests:

  • Unit tests that test an individual piece of functionality, or even just a single function
  • Integration tests that test a bunch of units together, like hitting an API or database
  • End to End tests where you use something like nigh****ch.js to test user stories, they basically automate actions in a browser.
  • Author

The new version of 'The Good Parts' is up - https://frontendmasters.com/courses/good-parts-javascript-web/. I'm not sure what the changes are, but it was filmed over 3 days. I'd expect some ES6 in there somewhere, especially classes.

 

On a side note, the book that he mentions at the very start called 'Thinking Fast and Slow' is fantastic.

The new version of 'The Good Parts' is up - https://frontendmasters.com/courses/good-parts-javascript-web/. I'm not sure what the changes are, but it was filmed over 3 days. I'd expect some ES6 in there somewhere, especially classes.

 

On a side note, the book that he mentions at the very start called 'Thinking Fast and Slow' is fantastic.

 

Crockford definitely isn't a fan of classes! and with good reason :)

 

I look forward to doing this, he is a superb teacher.

So many smart people in our industry! I was working through Dan Abramhov's Redux course just thinking how stupidly smart he is to have developed this insanely elegant library.

 

It's really nice.

 

Normally, I'll end up with a single component managing state with around 20 different methods, which can become difficult to maintain. Redux makes this much easier to manage.

So many smart people in our industry! I was working through Dan Abramhov's Redux course just thinking how stupidly smart he is to have developed this insanely elegant library.

 

You are talking about this course?

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.