coffeescript

关于 webpack 你所忽略的细节(附源码分析)

帅比萌擦擦* 提交于 2021-02-13 10:55:26
注:本篇不是入门教程,入门请直接查看官方文档。本篇的主要目标是通过实际问题来介绍 webpack 中容易被人忽略的细节, 以及源码分析( 以最新发布的 release 版本1.14.0的源码为例 ), 并且提供几种解决方案。 随着前端技术的火热发展,工程化,模块化和组件化的思想已逐步成为主流,与之相应的,就需要有一整套工具流可以支撑起它。 现在比较热门的前端资源模块化管理和打包工具应该非 Webpack 莫属了。 Webpack 是什么 它可以将许多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源。还可以将按需加载的模块进行代码分隔,等到实际需要的时候再异步加载。通过 loader 的转换,任何形式的资源都可以视作模块,比如 CommonJs 模块、 AMD 模块、 ES6 模块、CSS、图片、 JSON、Coffeescript、 LESS 等。 —引自 Webpack 中文指南 使用举例 我们来看一下官方文档中的最小用例,新建并写入以下内容到这两个文件: cats.js var cats = [ 'dave' , 'henry' , 'martha' ]; module .exports = cats; app.js (Entry Point) cats = require ( './cats.js' ); console .log(cats); 这个时候,就可以使用

Rails Stripe Api Error: Invalid source object: must be a dictionary or a non-empty string

妖精的绣舞 提交于 2021-02-11 11:59:25
问题 I have successfully implemented stripe credit card processing (Stripe api v2) into my rails app following this railscast tutorial http://railscasts.com/episodes/288-billing-with-stripe. After styling the form I started receiving the following error: There was a problem with your credit card. Invalid source object: must be a dictionary or a non-empty string. See API docs at https://stripe.com/docs' In my console I can see that the stripe_card_token is being submitted as any empty value

Rails Stripe Api Error: Invalid source object: must be a dictionary or a non-empty string

血红的双手。 提交于 2021-02-11 11:56:06
问题 I have successfully implemented stripe credit card processing (Stripe api v2) into my rails app following this railscast tutorial http://railscasts.com/episodes/288-billing-with-stripe. After styling the form I started receiving the following error: There was a problem with your credit card. Invalid source object: must be a dictionary or a non-empty string. See API docs at https://stripe.com/docs' In my console I can see that the stripe_card_token is being submitted as any empty value

Ember Uncaught RangeError: Maximum call stack size exceeded

大兔子大兔子 提交于 2021-01-29 05:01:19
问题 I'm trying to build a simple CRUD like EmberJS application that works on a single model. My routes look like this currently: Blog.ApplicationRoute = Ember.Route.extend() Blog.Router.map -> @route 'about' @resource 'posts', -> @route 'new' @resource 'post', { path: '/:post_id' }, -> @route 'edit' Blog.PostsRoute = Ember.Route.extend model: -> Blog.Post.find() Blog.PostsNewRoute = Ember.Route.extend model: -> Blog.Post.createRecord() events: save: -> console.log @ @.get('currentModel').get(

Accessing partial results of a FileReader in Firefox

♀尐吖头ヾ 提交于 2021-01-28 11:55:57
问题 I want to use a FileReader in my web application to partially load a CSV file into the browser. However, I am not able to access partial results in Firefox 27. My application requires only the first 100k bytes of the CSV file to populate a data preview. Therefore, I setup, start, and then abort the reader after a certain amount of data has been loaded. Here is an example that works fine in Chrome 35: warn = (a...) -> console.warn a... readFile = (file,cb,limit=1e5) -> warn "start reading file

Count sentences in string with JavaScript

允我心安 提交于 2020-12-10 07:22:19
问题 There are already a couple of similar questions: Splitting textarea sentences into array and finding out which sentence changed on keyup() JS RegEx to split text into sentences Javascript RegExp for splitting text into sentences and keeping the delimiter Split string into sentences in javascript My situation is a bit different. I need to count the number of sentences in a string. The closest answer to what I need would be: str.replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|") The only problem

Count sentences in string with JavaScript

偶尔善良 提交于 2020-12-10 07:22:07
问题 There are already a couple of similar questions: Splitting textarea sentences into array and finding out which sentence changed on keyup() JS RegEx to split text into sentences Javascript RegExp for splitting text into sentences and keeping the delimiter Split string into sentences in javascript My situation is a bit different. I need to count the number of sentences in a string. The closest answer to what I need would be: str.replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|") The only problem

How to get file size of newly created Image() if src is base64 string?

陌路散爱 提交于 2020-12-02 07:24:08
问题 How can I get the size of the newly created new Image() in bytes if this image's src is base64 data image? I have such coffeescript code: # This string is received after some original image preprocessing base64String = "data:image/jpeg;base64......" newImageObj = new Image() newImageObj.src = base64String newImageObj.onload = -> console.log "Resized image width is " + this.width console.log "New file size in bytes is " + newImageObj.fileSize The output is always like this: Resized image width

How to get file size of newly created Image() if src is base64 string?

一世执手 提交于 2020-12-02 07:22:12
问题 How can I get the size of the newly created new Image() in bytes if this image's src is base64 data image? I have such coffeescript code: # This string is received after some original image preprocessing base64String = "data:image/jpeg;base64......" newImageObj = new Image() newImageObj.src = base64String newImageObj.onload = -> console.log "Resized image width is " + this.width console.log "New file size in bytes is " + newImageObj.fileSize The output is always like this: Resized image width

Is it possible to define an infix function?

荒凉一梦 提交于 2020-12-01 03:56:46
问题 Is it possible to define my own infix function/operator in CoffeeScript (or in pure JavaScript)? e.g. I want to call a foo b or a `foo` b instead of a.foo b or, when foo is global function, foo a, b Is there any way to do this? 回答1: ES6 enables a very Haskell/Lambda calculus way of doing things. Given a multiplication function: const multiply = a => b => (a * b) You can define a doubling function using partial application (you leave out one parameter): const double = multiply (2) And you can