English 中文(简体)
Java 大型物体组合
原标题:Javascript modularising large objects

我只谈一个被定义为功能的物体,它掌握着许多方法和特性,用什么方法来组合,使其更易操作? 有可能将物体内的职能纳入外部档案?

Edit:

在一份答复中提及的包括其他档案,但该网页将有一个不全面的超文本。

<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script2.js"></script>
<script type="text/javascript" src="script3.js"></script>
....
<script type="text/javascript" src="script76.js"></script>

是否有办法制定该守则,因此只需要一个参考文件吗?

最佳回答
var myobj = {
  somefunc: function() { /* function code */ },
  prop: "some string",
  // etc.
};

以及上述法典后列入的另类卷宗

myobj.anotherfunc = function () { /* function code */ };
问题回答

http://requirejs.org/“rel=“nofollow” 它请你界定职能、单元、依附和从Javascript(可能称为ync)处装载外部 Java印档案。

您可以使用一台服务器的辅助工具处理你的 j印,而你甚至可以加快这一进程(如果时间不定)。

i m thinking of a script somthing like this: scripts.php

<?php 

$files = array( script1.js ,  script2.js );
$output =   ;

foreach($files as $file){
    $output .= file_get_contents($file);
}

header("Content-type: application/x-javascript");
echo $output;

?>

your html
<script type="text/javascript" src="/script.php"></script>

你们也可以仅仅把所有js档案放在一个夹子里,只是通过翻纸或一些东西制造阵列,而我想你们会得到这个想法!

问 题

You could try this:
http://www.cryer.co.uk/resources/javascript/script17_include_js_from_js.htm

......但最佳做法只是将你想要的档案列入主要html页。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签