coffeescript

CoffeeScript: Using instanceof vs Class.constructor.name

寵の児 提交于 2019-12-18 12:27:29
问题 If I have a class: class Haha constructor: (@lolAmount = 1) -> alert @lolAmount And I want to check if an object is of the right class, Is it always safe to use constructor.name : haha = new Haha() unless haha.constructor.name is 'Haha' throw Error 'Wrong type' or is it better to use instanceof : haha = new Haha() unless haha instanceof Haha throw Error 'Wrong type' One argument I have for instanceof is when using extends : class BigHaha extends Haha bigHaha = new BigHaha console.log bigHaha

How can I use Coffeescript 'this' from within jQuery $.bind()?

有些话、适合烂在心里 提交于 2019-12-18 12:26:34
问题 When using classes in Coffeescript, I've stumbled upon a major problem, let me illustrate class Bet constructor: () -> placeBet: -> $('#chips > div').bind 'click', -> amount = $(this).attr 'id' pile = $(this) switch amount when "ten" then this.bet pile, amount #This line causes a problem bet: (pile, amount) -> alert 'betting!' The call to this.bet above generates the following error: Uncaught TypeError: Object # has no method 'bet' So, currently the instance method of my class is not being

How to download images from a site with phantomjs

孤者浪人 提交于 2019-12-18 10:46:29
问题 I wanna save some images from a site. At the moment I can get the paths to the images but I have no clue how to get and save the images with phantomJs. findRotationTeaserImages = -> paths = page.evaluate -> jQuery('.rotate img').map(-> return this.src).get() for path, i in paths console.log(path); //save the image 回答1: I know this is an old question, but you do this pretty simply by storing the dimensions and location of each image on the in an object, then altering the phantomjs page

How can I compile CoffeeScript from .NET?

狂风中的少年 提交于 2019-12-18 10:08:42
问题 I want to write an HttpHandler that compiles CoffeeScript code on-the-fly and sends the resulting JavaScript code. I have tried MS [JScript][1] and IronJS without success. I don't want to use [Rhino][2] because the Java dependency would make it too difficult to distribute. How can CoffeeScript be compiled from .NET? 回答1: CoffeeScript-dotnet Command line tool for compiling CoffeeScript. Includes a file system watcher to automatically recompile CoffeeScripts when they change. Roughly equivalent

How to detect invalid route and trigger function in Backbone.Controller

筅森魡賤 提交于 2019-12-18 05:52:28
问题 Is there any method to detect invalid (or undefined) route and trigger 404 page in Backbone.Controller? I've defined routes in my Controller like this, but it didn't work. class MyController extends Backbone.Controller routes: "method_a": "methodA" "method_b": "methodB" "*undefined": "show404Error" # when access to /#method_a methodA: -> console.log "this page exists" # when access to /#method_b methodB: -> console.log "this also exists" # when access to /#some_invalid_hash_fragment_for

How to detect invalid route and trigger function in Backbone.Controller

喜欢而已 提交于 2019-12-18 05:52:25
问题 Is there any method to detect invalid (or undefined) route and trigger 404 page in Backbone.Controller? I've defined routes in my Controller like this, but it didn't work. class MyController extends Backbone.Controller routes: "method_a": "methodA" "method_b": "methodB" "*undefined": "show404Error" # when access to /#method_a methodA: -> console.log "this page exists" # when access to /#method_b methodB: -> console.log "this also exists" # when access to /#some_invalid_hash_fragment_for

Fabric.js eraser issue canvas

烂漫一生 提交于 2019-12-18 05:45:10
问题 I want to implement eraser in my web app using Fabric.js. Is there any way to implement eraser in Fabric.js? For example, such as in MS Paint? 回答1: There's no built-in eraser in Fabric and implementing is a bit difficult. The thing about Fabric is that everything is object-based and most of the things are also vector-based. Unlike with native canvas, we can't just erase some pixels on a global bitmap. We have entire object model underneath, and canvas output is a simple loop of all those

CoffeeScript Existential Operator and this

自作多情 提交于 2019-12-18 04:45:09
问题 I noticed something a little odd with the CoffeeScript compilier and was wondering if this was correct behavior or not. If it is correct I'm curious why there is a difference.. Given the following CoffeeScript: if @myVar? alert myVar I was expecting it to compile to JavaScript like this: if (typeof this.myVar !== "undefined" && this.myVar !== null) { alert(myVar); } But instead what the CoffeeScript compiler outputs is this: if (this.myVar != null) { alert(myVar); } If I don't reference this

AngularJS: How do I create controllers in multiple files

白昼怎懂夜的黑 提交于 2019-12-18 04:29:19
问题 I'm trying to split my controllers into multiple files, but when i try to register them at my module im getting an error: groupcontroller.coffee app = angular.module('WebChat', []); app.controller 'GroupController', ($scope) -> usercontroller.coffee app = angular.module('WebChat', []); app.controller 'UserController', ($scope) -> Error Error: Argument 'GroupController' is not a function, got undefined From the documentation I dont really get what the module method does anyway. Does it store

error installing coffeescript on mac 10.7.2

邮差的信 提交于 2019-12-18 04:08:37
问题 Node and npm are both installed and up to date but keep getting this error when trying to install coffeescript. I am still new to programming so any advice would be greatly appreciated. test-macbook:~ Test$ npm -v 1.1.0-3 test-macbook:~ Test$ node -v v0.6.8 test-macbook:~ Test$ npm install -g coffee-script npm http GET https://registry.npmjs.org/coffee-script npm http 304 https://registry.npmjs.org/coffee-script npm ERR! Could not create /usr/local/lib/node_modules/___coffee-script.npm npm