绑定对象的函数里的 this 到对象本身。

使用 Array.prototype.forEach() 来遍历对象里所有指定的函数,使用 Function.prototype.apply() 来指定函数中 this 的上下文为对象本身,再覆盖原先的函数。

继续阅读 30秒学会 JavaScript 片段 – bindAll

从列表的尾部开始删除元素,直到传入的遍历函数返回 true,然后返回剩下的元素。

使用 List.lastIndexWhere() 来遍历执行 test 函数,以找到最后一个满足条件的元素。如果未找到,返回空数据;否则使用 List.sublist() 来返回剩下的元素。

继续阅读 30秒学会 Dart 片段 – dropRightWhile

Groups the elements into two arrays, depending on the provided function’s truthiness for each element.

Use Array.prototype.reduce() to create an array of two arrays.
Use Array.prototype.push() to add elements for which fn returns true to the first array and elements for which fn returns false to the second one.

继续阅读 30秒学会 JavaScript 片段 – partition

Creates a function that invokes the provided function with its arguments arranged according to the specified indexes.

Use Array.prototype.map() to reorder arguments based on indexes in combination with the spread operator (...) to pass the transformed arguments to fn.

继续阅读 30秒学会 JavaScript 片段 – rearg

Curries a function.

Use recursion.
If the number of provided arguments (args) is sufficient, call the passed function fn.
Otherwise, return a curried function fn that expects the rest of the arguments.
If you want to curry a function that accepts a variable number of arguments (a variadic function, e.g. Math.min()), you can optionally pass the number of arguments to the second parameter arity.

继续阅读 30秒学会 JavaScript 片段 – curry

A hook that handles the event of clicking outside of the wrapped component.

  • Create a custom hook that takes a ref and a callback to handle the click event.
  • Use the React.useEffect() hook to append and clean up the click event.
  • Use the React.useRef() hook to create a ref for your click component and pass it to the useClickOutside hook.

继续阅读 30秒学会 React 片段 – useClickOutside

Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.

  • position: relative on the element establishes a Cartesian positioning context for pseudo elements.
  • :after defines a pseudo element.
  • background-image: url(...) adds the SVG shape (a 24×12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use the URL-encoder for SVG.
  • position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  • width: 100% ensures the element stretches the entire width of its parent.
  • height: 12px is the same height as the shape.
  • bottom: 0 positions the pseudo element at the bottom of the parent.

继续阅读 30秒学会 CSS 片段 – Shape separator