简体   繁体   English

如何在节点上使用YUI3?

[英]How to use YUI3 on node?

I can't get YUI3 to work on node. 我无法在节点上使用YUI3。

I have installed all dependencies according to this site: http://github.com/yui/nodejs-yui3 . 我已经根据该站点安装了所有依赖项: http : //github.com/yui/nodejs-yui3

Here is my code: 这是我的代码:

var jsdom  = require("jsdom").jsdom,
    window = jsdom("<html><head></head><body>hello world</body></html>").createWindow();

var puts = require("sys").puts;
var YUI = require("yui3").YUI;

var person = {
    name: "Ajsie",
    age: 25,
    greet: function() {
        puts("Hello World! My name is " + this.name + " and I am " + this.age + " years old")
    }
}

result = YUI.Object(person);

puts(result);

Here is the output on terminal: 这是终端上的输出:

node.js:50
    throw e;
    ^
TypeError: Object function () {
        var i = 0,
            Y = this,
            args = arguments,
            l = args.length,
            gconf = (typeof YUI_config !== 'undefined') && YUI_config;

        if (!(Y instanceof YUI)) {
            Y = new YUI();
        } else {
            // set up the core environment
            Y._init();
            if (gconf) {
                Y.applyConfig(gconf);
            }
            // bind the specified additional modules for this instance
            if (!l) {
                Y._setup();
            }
        }

        if (l) {
            for (; i < l; i++) {
                Y.applyConfig(args[i]);
            }

            Y._setup();
        }

        return Y;
    } has no method 'Object'
    at Object.<anonymous> (/Volumes/Private/ajsie/Projects/icdev/javascript/node/object.js:15:14)
    at Module._compile (node.js:324:23)
    at Object..js (node.js:332:12)
    at Module.load (node.js:254:25)
    at Object.runMain (node.js:346:24)
    at Array.<anonymous> (node.js:595:12)
    at EventEmitter._tickCallback (node.js:42:22)
    at node.js:607:9

It says "has no method "Object". 它说“没有方法“对象”。

What is the problem? 问题是什么?

The code should look like this: 该代码应如下所示:


var jsdom  = require("jsdom").jsdom,
    window = jsdom("hello world").createWindow();

var puts = require("sys").puts;
var YUI = require("yui3").YUI;


YUI().use(function(Y){
    var person = {
        name: "Ajsie",
        age: 25,
        greet: function() {
            puts("Hello World! My name is " + this.name + " and I am " + this.age + " years old");
        }
    }

    var result = Y.Object(person);
    puts(result);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM