0

I'm having a strange issue, possabily a really noob one, but for the life of me I can't get node module.exports to work for me.

Here is my route (routes/about.js)

var About = (function () {
    function About() {
        this.init();
    }
    About.prototype.init = function () {
        console.log('init');
    };
    About.prototype.me = function (req, res) {
        this.init();
        res.json([
            'jamie was here'
        ]);
    };
    return About;
})();


module.exports = About;

and my app.js

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , about = require('./routes/about')
  , http = require('http')
  , path = require('path');

var app = express();
about = new about;
console.log(about);
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/me/?', about.me);
http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

When about.me is called, i get a "TypeError: Object # has no method 'init'" error...

Any help would be greatly appreciated!


one quick solution below.. Cheers

public class Main {

public static void main(String[] args) {
    String s = "X";
    int totalColumns = 4;
    int totalRow = 3;

    colums(s, totalColumns);
    rows(s, totalColumns, totalRow);
    colums(s, totalColumns);


}

private static void colums(String cs, int cc) {
    for (int i = 0; i < cc; i++) {
        System.out.print(cs);
    }

}

private static String whitespace(int tc) {
    String ws = " ";
    for (int i = 1; i < tc - 2; i++) {
        ws += " ";
    }
    return ws;
}

private static void rows(String rs, int tc, int tr) {
    System.out.println();
    for (int i = 0; i < tr - 2  ; i++) {
        System.out.println(rs + whitespace(tc) + rs);
    }
}

}

4

1 に答える 1

-1

私はちょうどそれを解決しました!愚かな間違い。

オブジェクト自体ではなく、 me 関数への参照を渡しています。なぜそれが存在しないのも不思議ではありません!

于 2013-04-07T04:40:25.913 に答える