English 中文(简体)
结晶:在从浏览器中排出时,不需要承认
原标题:CoffeScript: require not recognized when runninjg from the browser

I am trying to run this piece of code taken from http://coffeescriptcookbook.com embedding it into an html.

net = require  net 

domain =  localhost 
port = 9001

connecting = (socket) ->
    console.log "Connecting to real-time server"

connection = net.createConnection port, domain

connection.on  connect , () ->
    console.log "Opened connection to #{domain}:#{port}"
    connecting connection

connection.on  data , (data) ->
    console.log "Received: #{data}"

connection.on  end , (data) ->
    console.log "Connection closed"

该法典有名客户。 coffe,一经咖啡指挥部管理:咖啡客户。 coffe, 进行罚款,与服务器连接,但当我在html的档案中加以利用并开启时,就会产生这一错误: 不详:没有界定要求。

My html script tags looks like this:

 <script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"
         type="text/javascript" charset="utf-8" ></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"
         type="text/javascript" charset="utf-8"></script>
    <script src="{% get_static_prefix %}functions.js"
         type="text/javascript" charset="utf-8"></script>
    <script src="{% get_static_prefix %}jquery.dajax.core.js"
         type="text/javascript" charset="utf-8"></script>

    <script src="{% get_static_prefix %}client.coffee"
         type="text/coffeescript" charset="utf-8"></script>

任何想法?

最佳回答

这在浏览器中赢得了一定的工作。

第一期: 由于安全原因,浏览器的拖网只允许与其他服务器或港口连接。 而且,你没有获得真正的资金,只是吉大港山区。

第二期:require 不是 no。 j 只指示你在 no子里使用(即,当你手上有<代码>node的javascript文档或带<编码>的咖啡封面文件时)。 模块属于代号,永远不会以这种方式在浏览器上运行。

If you want to talk to the server in realtime from inside the browser, I recommend the socket.io module which uses websockets, flashsockets and HTTP (those are usable from within the browser).

问题回答




相关问题
How do I define global variables in CoffeeScript?

On Coffeescript.org: bawbag = (x, y) -> z = (x * y) bawbag(5, 10) would compile to: var bawbag; bawbag = function(x, y) { var z; return (z = (x * y)); }; bawbag(5, 10); compiling via ...

I m trying to re-write this in CoffeeScript. Coming unstuck

function getElementsByClassName(className) { // get all elements in the document if (document.all) { var allElements = document.all; } else { var allElements = document.getElementsByTagName("...

Anonymous functions syntax in CoffeeScript

I ve been looking at CoffeeScript and I m not understanding how you would write code like this. How does it handle nested anonymous functions in its syntax? ;(function($) { var app = $....

Why are my CoffeeScript/backbone.js events not firing?

I m trying to familiarize myself with CoffeeScript and backbone.js, and I must be missing something. This CoffeeScript: MyView = Backbone.View.extend events: { "click" : "testHandler" ...

Custom compiler with maven

I m trying to make Maven2 to compile coffeescript to javascript. As far as I m concerned there is no plugin which provides compiling coffeescript. Is there a compiler-plugin for maven which can be ...

what is wrong when I compile my .coffee files

Hi there Iam using coffeeScript for my apps now and I love it but recently I ve been having a lot of trouble with compilation, Iam using it for a rails application and when I run coffee -w -c public/...

CoffeeScript on Windows?

How can I try CoffeeScript on Windows? The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation EDIT: Since I asked this a while ago, many new ...

How can I compile CoffeeScript from .NET?

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][...

热门标签