Yahoo Web Search

Search results

  1. Dictionary
    Mod·ule
    /ˈmäjo͞ol/

    noun

    • 1. each of a set of standardized parts or independent units that can be used to construct a more complex structure, such as an item of furniture or a building.
  2. People also ask

  3. 2 days ago · Modules — Python 3.12.3 documentation. 6. Modules ¶. If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that ...

  4. There are actually three different ways to define a module in Python: A module can be written in Python itself. A module can be written in C and loaded dynamically at run-time, like the re ( regular expression) module. A built-in module is intrinsically contained in the interpreter, like the itertools module.

  5. A module is a distinct assembly of components that can be easily added, removed or replaced in a larger system. Generally, a module is not functional on its own. In computer hardware, a module is a component that is designed for easy replacement. In computer software, a module is an extension to a main program dedicated to a specific function.

    • Gavin Wright
    • Overview
    • A background on modules
    • Browser compatibility
    • Introducing an example
    • Basic example structure
    • Exporting module features
    • Importing features into your script
    • Importing modules using import maps
    • Applying the module to your HTML

    This guide gives you all you need to get started with JavaScript module syntax.

    JavaScript programs started off pretty small — most of its usage in the early days was to do isolated scripting tasks, providing a bit of interactivity to your web pages where needed, so large scripts were generally not needed. Fast forward a few years and we now have complete applications being run in browsers with a lot of JavaScript, as well as JavaScript being used in other contexts (Node.js, for example).

    It has therefore made sense in recent years to start thinking about providing mechanisms for splitting JavaScript programs up into separate modules that can be imported when needed. Node.js has had this ability for a long time, and there are a number of JavaScript libraries and frameworks that enable module usage (for example, other CommonJS and AMD-based module systems like RequireJS, and more recently Webpack and Babel).

    The good news is that modern browsers have started to support module functionality natively, and this is what this article is all about. This can only be a good thing — browsers can optimize loading of modules, making it more efficient than having to use a library and do all of that extra client-side processing and extra round trips.

    Use of native JavaScript modules is dependent on the import and export statements; these are supported in browsers as shown in the compatibility table below.

    javascript.statements.import

    BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

    javascript.statements.export

    BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

    To demonstrate usage of modules, we've created a simple set of examples that you can find on GitHub. These examples demonstrate a simple set of modules that create a element on a webpage, and then draw (and report information about) different shapes on the canvas.

    These are fairly trivial, but have been kept deliberately simple to demonstrate modules clearly.

    In our first example (see basic-modules) we have a file structure as follows:

    The modules directory's two modules are described below:

    •canvas.js — contains functions related to setting up the canvas:

    •create() — creates a canvas with a specified width and height inside a wrapper with a specified ID, which is itself appended inside a specified parent element. Returns an object containing the canvas's 2D context and the wrapper's ID.

    •createReportList() — creates an unordered list appended inside a specified wrapper element, which can be used to output report data into. Returns the list's ID.

    •square.js — contains:

    The first thing you do to get access to module features is export them. This is done using the export statement.

    The easiest way to use it is to place it in front of any items you want exported out of the module, for example:

    You can export functions, var, let, const, and — as we'll see later — classes. They need to be top-level items; you can't use export inside a function, for example.

    A more convenient way of exporting all the items you want to export is to use a single export statement at the end of your module file, followed by a comma-separated list of the features you want to export wrapped in curly braces. For example:

    Once you've exported some features out of your module, you need to import them into your script to be able to use them. The simplest way to do this is as follows:

    You use the import statement, followed by a comma-separated list of the features you want to import wrapped in curly braces, followed by the keyword from, followed by the module specifier.

    The module specifier provides a string that the JavaScript environment can resolve to a path to the module file. In a browser, this could be a path relative to the site root, which for our basic-modules example would be /js-examples/module-examples/basic-modules. However, here we are instead using the dot (.) syntax to mean "the current location", followed by the relative path to the file we are trying to find. This is much better than writing out the entire absolute path each time, as relative paths are shorter and make the URL portable — the example will still work if you move it to a different location in the site hierarchy.

    So for example:

    becomes

    You can see such lines in action in main.js.

    Above we saw how a browser can import a module using a module specifier that is either an absolute URL, or a relative URL that is resolved using the base URL of the document:

    Import maps allow developers to instead specify almost any text they want in the module specifier when importing a module; the map provides a corresponding value that will replace the text when the module URL is resolved.

    For example, the imports key in the import map below defines a "module specifier map" JSON object where the property names can be used as module specifiers, and the corresponding values will be substituted when the browser resolves the module URL. The values must be absolute or relative URLs. Relative URLs are resolved to absolute URL addresses using the base URL of the document containing the import map.

    The import map is defined using a JSON object inside a

    With this map you can now use the property names above as module specifiers. If there is no trailing forward slash on the module specifier key then the whole module specifier key is matched and substituted. For example, below we match bare module names, and remap a URL to another path.

    If the module specifier has a trailing forward slash then the value must have one as well, and the key is matched as a "path prefix". This allows remapping of whole classes of URLs.

    Now we just need to apply the main.js module to our HTML page. This is very similar to how we apply a regular script to a page, with a few notable differences.

    First of all, you need to include type="module" in the

    You can also embed the module's script directly into the HTML file by placing the JavaScript code within the body of the

    The script into which you import the module features basically acts as the top-level module. If you omit it, Firefox for example gives you an error of "SyntaxError: import declarations may only appear at top level of a module".

    Code sample

    index.html
    main.js
    modules/
      canvas.js
      square.js
  6. Definition of module noun in Oxford Advanced Learner's Dictionary. Meaning, pronunciation, picture, example sentences, grammar, usage notes, synonyms and more.

  7. Dec 20, 2023 · A Python module is a file containing Python definitions and statements. A module can define functions, classes, and variables. A module can also include runnable code. Grouping related code into a module makes the code easier to understand and use. It also makes the code logically organized.

  8. May 3, 2024 · A module in Python is a file containing statements and definitions. It can define functions, classes, and variables, and can also include runnable code. Modules are used to organize code into logical units, to reduce complexity and increase reusability. You can import modules into your program using the import statement.

  1. People also search for