实现这样的目标需要什么?

时间:2015-07-29 13:47:40

标签: javascript jquery

我的问题不是关于编程技巧,而是关于lib文件和框架文件。例如,我已经拥有:jquery.js&amp; jquery.ui.js到位,在<header>块中声明。

假设我在JavaScript文件中定义了一些内容,如下所示:

define("app/ui/dialogs/delete_tweet_dialog", ["module", "require", "exports", "core/component", "app/ui/with_dialog", "app/ui/dialogs/with_modal_tweet"], function(module, require, exports) {
    function deleteTweetDialog() {
        this.defaultAttrs({
            cancelSelector: ".cancel-action",
            deleteSelector: ".delete-action"
        }), this.openDeleteTweet = function(a, b) {
            this.attr.sourceEventData = b, this.displayTweet(b.tweetId, {
                modal: "delete"
            }), this.id = b.id, this.open()
        }, this.deleteTweet = function() {
            this.trigger("uiDidDeleteTweet", {
                id: this.id,
                sourceEventData: this.attr.sourceEventData
            })
        }, this.deleteTweetSuccess = function(a, b) {
            this.trigger("uiDidDeleteTweetSuccess", this.attr.sourceEventData), this.close()
        }, this.restoreFocusToTweet = function(a) {
            $(a.target).is(this.$dialog) && this.activeEl && this.trigger($(this.activeEl).closest(".tweet"), "uiShouldAddFocusStyle")
        }, this.after("initialize", function() {
            this.on("click", {
                cancelSelector: this.close,
                deleteSelector: this.deleteTweet
            }), this.on(document, "uiOpenDeleteDialog", this.openDeleteTweet), this.on(document, "dataDidDeleteTweet", this.deleteTweetSuccess), this.on(document, "uiDialogRestorePreviousFocus", this.restoreFocusToTweet), this.on(document, "uiCloseDeleteTweetDialog", this.close)
        })
    }
    var defineComponent = require("core/component"),
        withDialog = require("app/ui/with_dialog"),
        withModalTweet = require("app/ui/dialogs/with_modal_tweet"),
        DeleteTweetDialog = defineComponent(deleteTweetDialog, withDialog, withModalTweet);
    module.exports = DeleteTweetDialog
});  
  • 如何使上述代码正常工作?
  • jQuery.js是否单独提供[module,require,exports],还是需要添加其他东西?
  • 一旦我做了类似于这个的定义,我怎么能从其他代码中调用它?

我发现了这个:

定义(     module_id / 可选 /,     [dependencies] / 可选 /,     定义函数/ 用于实例化模块或对象的函数 / );

来自:http://addyosmani.com/writing-modular-js/

但是,我仍然不明白如何调用定义?没有关于Google的教程。

1 个答案:

答案 0 :(得分:0)

您展示的代码是作为AMD编写的。 UPDATE tng_managedobject SET propagate_status = 0 WHERE severity <> 0 AND class_name like('Plaza_VES_Junction_Box') 是这里可能使用的库。

在此处详细了解:http://requirejs.org/