coffeescript

Using filter on directive attribute causes infinite loop in $digest cycle

牧云@^-^@ 提交于 2019-12-20 02:52:19
问题 An attempt to use a filter on a directive with isolate scope: <div tags="p.tags | refTags"></div> Causes an infinite loop in the $digest cycle: This error occurs when the application's model becomes unstable and each $digest cycle triggers a state change and subsequent $digest cycle. Angular detects this situation and prevents an infinite loop from causing the browser to become unresponsive. .directive 'tags', -> restrict: 'A' scope: tags: '=' templateUrl: 'partials/tags.html' .filter

Atom editor: snippet for inserting a timestamp

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 02:28:28
问题 Below is an Atom snippet I was playing with. What I want to do is insert a timestamp with a developer's name at the end. This is useful when multiple folks are working on the same codebase and you need to comment out some code or add a comment. This way other developers know who did what, and when they did it. I've found it very useful and wanted to create a snippet to do this. However, as you can see from the snippet, it's very ugly...JS is not my forte. Is there a clean way to do this? time

Top-level variables aren't globally-scoped and return values are mandatory in CoffeeScript

 ̄綄美尐妖づ 提交于 2019-12-20 01:43:37
问题 funName = () -> $(".foo").addClass("bar"); Compiles into the scope of an anonymous function. Calling funName from the console results in undefined . (function() { var funName; funName = function() { return $(".foo").addClass("bar"); }; }).call(this); What's its reasoning for compiling like this and how do I work with it? Also any insight on the mandatory return within functions using CoffeeScript would be great. Why is it like that? How do I need to code differently because of it? 回答1: Mike

Index variable (_i) in for loops?

…衆ロ難τιáo~ 提交于 2019-12-20 01:11:08
问题 Take a look at this simple code: eat = (x) -> console.log "nom", x # dog only eats every second cat feast = (cats) -> eat cat for cat in cats when _i % 2 == 0 feast ["tabby cat" "siamese cat" "norwegian forest cat" "feral cat" "american bobtail" "manx"] $ coffee a.coffee nom tabby cat nom norwegian forest cat nom american bobtail It seems the _i variable is the current index. Is this a feature, bug, or NaN? I haven't heard anyone else talking about this, so I wonder if there's some reason I

How to properly set up Coffeescript with Node.js

空扰寡人 提交于 2019-12-19 19:49:08
问题 I'm trying to define some Node routes using Coffeescript in the following way: My app.js file: /** * Module dependencies. */ require('coffee-script'); var express = require('express'); var http = require('http'); var path = require('path'); var app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.json()); app

Is it possible to define a dynamically named property using object literal in JavaScript?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 17:15:09
问题 Consider the following var a = {foo: "bar"}; Equivalent to var a = {}; a.foo = "bar"; Equivalent to var a = {}; a['foo'] = "bar"; Equivalent to var a = {} var b = "foo"; a[b] = "bar"; Is it possible to do something like var b = "foo"; var a = { [b]: "bar" }; Such that the result would be // => {foo: "bar"} Acceptable solutions are in JavaScript or CoffeeScript 回答1: No. There is no way to do it using object literal notation. UPDATE: According to the ECMAScript standard 6.0 you are now able to

Requiring external js file for mocha testing

試著忘記壹切 提交于 2019-12-19 13:48:10
问题 So I'm playing around with BDD and mocha with my express.js project. I'm just getting started so here is what I have as my first test case: should = require "should" require "../lib/models/skill.js" describe 'Skill', -> describe '#constructor()', -> it 'should return an instance of class skill', -> testSkill = new Skill "iOS", "4 years", 100 testSkill.constructor.name.should.equal 'Skill' (also this coffeescript generates some odd looking js since it inserts returns to last statement.. is

How to load external template synchronously with backbone

不羁岁月 提交于 2019-12-19 11:56:35
问题 I'm trying to build a mobile application with phonegap, backbone.js and coffeescript. I want to do something like this : class MyApplication.Views.EntriesIndex extends Backbone.View template: load('my/template') //It will load the external file my/template.tpl render: -> $(@el).html(@template()) this I want to load it synchronously. I already seen require.js but I find it's too complicated for this simple think. I seen than I can use JST for a rails application but I don't find how to use it

How do I refer to actual 'this' inside CoffeeScript fat-arrow callback?

别来无恙 提交于 2019-12-19 10:08:56
问题 The title says it all. When I use the fat-arrow in CoffeeScript, it stores this first before calling the function. For example: class myClass constructor: -> element = $ "#id" element.click -> @myMethod(@value) return return myMethod: (c)-> window.console.log(c) return would yield var myClass; myClass = (function() { function myClass() { var element; element = $("#id"); element.click(function() { this.myMethod(this.value); }); return; } myClass.prototype.myMethod = function(c) { window

How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?

☆樱花仙子☆ 提交于 2019-12-19 06:26:09
问题 I'm making some 3D text using WebGL , three.js , and THREE.TextGeometry . It's working fine so far. I'm able to create a single line of 3D text. Now I want to create multiline text, like a short paragraph. Preferably, I'd like it to wrap naturally when it reaches the border of a box/rectangle its placed it in. I want a similar behavior that standard HTML text has when it's inside of a div, wrapping to multiple lines when it reaches the edge of it's parent div. Here's how I'm creating a single