coffeescript

Is there any way to not return something using CoffeeScript?

南笙酒味 提交于 2019-12-17 04:47:12
问题 It seems like CoffeeScript automatically returns the last item in a scope. Can I avoid this functionality? 回答1: You have to explicitly return nothing, or to leave an expression evaluating to undefined at the bottom of your function: fun = -> doSomething() return Or: fun = -> doSomething() undefined This is what the doc recommends, when using comprehensions: Be careful that you're not accidentally returning the results of the comprehension in these cases, by adding a meaningful return value —

How can I use option “--bare” in Rails 3.1 for CoffeeScript?

核能气质少年 提交于 2019-12-17 03:42:38
问题 Someone know how can I use this option in Rails 3.1? Now CoffeScript puts a function with .call(this) on each file, but I want to remove this. EDIT: "Can't find variable” error with Rails 3.1 and Coffeescript" and "Pattern for CoffeeScript modules" have what I want. I'll change my global vars to use @global scope. 回答1: I'd recommend against doing this. See my answer at Pattern for CoffeeScript modules for some of the reasons why. ("Making your CoffeeScript code incompatible with out-of-the

How can I use option “--bare” in Rails 3.1 for CoffeeScript?

ぃ、小莉子 提交于 2019-12-17 03:42:10
问题 Someone know how can I use this option in Rails 3.1? Now CoffeScript puts a function with .call(this) on each file, but I want to remove this. EDIT: "Can't find variable” error with Rails 3.1 and Coffeescript" and "Pattern for CoffeeScript modules" have what I want. I'll change my global vars to use @global scope. 回答1: I'd recommend against doing this. See my answer at Pattern for CoffeeScript modules for some of the reasons why. ("Making your CoffeeScript code incompatible with out-of-the

Null-safe property access (and conditional assignment) in ES6/2015

岁酱吖の 提交于 2019-12-17 00:01:04
问题 Is there a null -safe property access (null propagation / existence) operator in ES6 (ES2015/JavaScript.next/Harmony) like ?. in CoffeeScript for example? Or is it planned for ES7? var aThing = getSomething() ... aThing = possiblyNull?.thing This will be roughly like: if (possiblyNull != null) aThing = possiblyNull.thing Ideally the solution should not assign (even undefined ) to aThing if possiblyNull is null 回答1: Update (2019-06-27): Seems people are still finding this, here's the current

Backbone view el not defined

萝らか妹 提交于 2019-12-14 03:49:45
问题 I have this code - class TableManager tables : {} tableViews :{} nextId : 0 rootEl : 'body' addTable:(json,el)-> newTableModel = new TableModel(json,@nextId) newTableModel @tables[@nextId] = newTableModel el = "#table1" newView = new TableView({model : newTableModel, columns : json["Columns"], el : el, id : @nextId}) @tableViews[@nextId] = newView newTableModel.renderModel() @nextId++ class TableView extends Backbone.View tableId : '' columns : '' thead : '' tbody : '' input : '' rows : ''

iOS JSON troubles on actual device

只谈情不闲聊 提交于 2019-12-14 03:44:43
问题 For some reason, this works on the emulator running iOS 6+ but not on an actual iPad running iOS 5+. When I run it my app on the iPad it gives me this error (and others). Error parsing JSON: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Badly formed object around character 316.) UserInfo=0x650260 {NSDebugDescription=Badly formed object around character 316.} JSON used is this (which is passed from Javascript): {"functionname":"setItem",

How can search a string to see if it contains all substrings?

笑着哭i 提交于 2019-12-14 03:31:47
问题 I will be using coffeescript/javascript/jquery and I need to return true if a string contains all of my substrings. So, lets say that I have an array of substrings 'my', 'dog', 'spot'. I need to return a true if my string is 'growing up my pet dog was named spot'. But I would need to return false if the string was 'I had a dog named spot'. I am thinking there is a way to do this with a regular expression, but can't seem to figure it out? 回答1: var mystring = "growing up my pet dog was named

Anonymous function works as callback but defined function does not

我是研究僧i 提交于 2019-12-14 03:21:35
问题 I have a module that looks like this: module.exports = AtomMarkdownLabels = # other stuff here file_changed_added: (file_path) => fs.readFile file_path, 'utf-8', @process_yaml console.log 'file changed' process_yaml: (err, data) => console.log "process_yaml is called" I know file_changed_added is being called from some other function and I'm seeing the "file changed" output in the console, but process_yaml isn't if I change file_changed_added to file_changed_added: (file_path) => fs.readFile

Order of executing requests with AngularJS's ng-resource? Pt2

让人想犯罪 __ 提交于 2019-12-14 03:03:29
问题 This is a follow-up question to Part1. Part 2: books_ctrl.js.coffee myApp.controller "BooksCtrl", ($scope, Book) -> $scope.save = () -> if $scope.book.id? Book.update($scope.book) else Book.save($scope.book) $scope.book = {} $scope.getBooks() book.js.coffee myApp.factory "Book", ($resource) -> $resource("/books/:id", {id: "@id"}, {update: {method: "PUT"}}) Rails Server Development Log Started GET "/books" for 127.0.0.1 at 2014-07-03 12:53:07 +0200 Processing by BooksController#index as JSON

Coffeescript/Javascript variable scope

混江龙づ霸主 提交于 2019-12-14 01:01:09
问题 I'm not really sure why i do not have access to the @date (this.date) variable from the context of the anonymous function defined in C.f() class C constructor: () -> @date = new Date() f: () -> $(document).keydown( (e) -> alert(@date) ) Could someone comment on that? 回答1: This is happening because inside the keydown event handler, the this value will not refer to your object, it will refer to the DOM element. For that purpose, you can use => (the fat arrow), that will bind the handler's this