Alibabacloud.com offers a wide variety of articles about modular programming with python, easily find your modular programming with python information here online.
JavaScript Modular Programming (III): The use of Require.js
Author: Ruan Yi Feng
Date: November 7, 2012
The first and second sections of this series introduce JavaScript module prototypes and theoretical concepts, and today we describe how they can be used in combat.
I'm using a very popular library require.js.
First, why use Require.js.
At the earliest, all of the JavaScript code was written in a file, a
This article contains the basics of Linux driver modular programming, including the creation of multi-threading, latency, and makefileWith an example to illustrate#include #include#include#include#include#include#include#include#include#include#include#include#include#include#include#include"gpio-sama5d3-test.h"//if there is no corresponding. h file, please note//staticdeclare_completion (my_completion);Sta
Modular programming with functions (II.)First, nested calls to functionsThe function definition of C language is parallel and independent to each other. That is, functions cannot be nested, but can be nested to call functions. That is, in the process of calling a function, another function can be calledExecution process,Example: Enter 4 integers to find the largest number. Handled using nested calls to func
As projects become more and more, the reuse of code becomes extremely important, and it is time to do modular programming, which is to make a separate module of some common components or libraries, and other items to be referenced directly. Android libraries are the most common for Android development, and the way to refer to the Android library before Gradle appears is cumbersome, but with gradle everythin
Require.js implementation of JS Modular Programming (ii): Requirejs OptimizerIn this section, we mainly study the use of an optimization tool r.js provided by Require.js.1, know Requirejs OptimizerRequirejs Optimizer is the optimization of the script to support the current popular UGLIFYJS and Closure Compiler Two compression methods, UGLIFYJS need NodeJS environment support, and Closure Compiler need Java
Modular drive testing, is to learn from the programming language of the modular thinking, the repeated operation of the independent success of the announcement module, understand the use of this module during the execution of the case is called when the operation is required, which can greatly eliminate duplication and improve the maintainability of test casesThe
not empty, and the first line is not "#!/bin/bash", then the error and exit; If the first line is "#!/bin/bash", use vim to open the script; position the cursor directly to the last line4. When the script is turned off, determine if the script has a syntax errorIf there is, prompt to enter Y to continue editing, enter N to discard and exit;If not, give this file permission to execute;#!/bin/bash# #mkscript .sh[-d|--description "scriptdescription"][-a|--author "script author "]/path/to/somefilew
introduction of the resource is not very full, so it will be an error, can be directly ignored, because the implementation of the UI plugin is said to have been successful.
The problem of Requirejs using Jquery-ui
Because Requirejs loads the JS file and executes immediately, if your jquery UI plugin needs to refresh the DOM page, it may cause the page event to fail.
For example, when your module is loaded, the Click event is bound to an element of the page $ (' #test '). However, using a UI
...). Not recommended).
For example, in the DOM refactoring JS module, execute the render code below:
Require ("XXX"). initevents (); Common scenarios:
For example, I use the Jquery-steps UI plugin on the page, which will render the page again. This causes my first binding event to fail .... Only postpone to this JS refactor the page, and then bind the line.
The above is based on REQUIREJS and jquery Modular
() accepts a configuration object that, in addition to the paths property mentioned previously, has a shim property that is specifically designed to configure incompatible modules. Specifically, each module defines (1) The exports value (the output variable name), indicating the name of the external invocation of the module, and (2) An array of deps that indicates the dependency of the module. For example, the plugin for jquery can be defined like this:Shim: { ' Jquery.scroll ': {deps: [' jquer
IifeFull spelling imdiately invoked function expression, which executes immediately.Grammarvar module1 = (function() { var _count = 0; varfunction() { //... }; varfunction() { //... }; return {m1:m1, m2:m2}; })();Using the notation above, the external code cannot read the internal _count variable.The meaning of parentheses1. function(){} The meaning of the enclosed bracketsThe purpose of this parenthesis is to convert function(){} to an expression. Easy to implement. If the parent
dependency of the module. For example, the plugin for jquery can be defined like this:
Shim: {
' Jquery.scroll ': {
Deps: [' jquery '],
Exports: ' JQuery.fn.scroll '
}
}
Seven, Require.js plug-in Require.js also offers a range of plugins for specific functions. The Domready plugin allows the callback function to run after the page DOM structure has been loaded.
Require ([' domready! '], function (DOC) {
Called Once the DOM is ready
});
define their characteristics.Require.config ({shim: {' Underscore ': {exports: ' _ '},' Backbone ': {deps: [' underscore ', ' jquery '],Exports: ' Backbone '}}});Require.config () accepts a configuration object that, in addition to the paths property mentioned previously, has a shim property that is specifically designed to configure incompatible Modules. specifically, Each module defines (1) the exports value (the output variable name), indicating the name of the external invocation of the mod
, the plugin for jquery can be defined like this:
Shim: {
' Jquery.scroll ': {
Deps: [' jquery '],
Exports: ' JQuery.fn.scroll '
}
}
Seven, Require.js plug-inRequire.js also offers a range of plugins for specific functions.The Domready plugin allows the callback function to run after the page DOM structure has been loaded.
Require ([' domready! '], function (DOC) {
Called Once the DOM is ready
});
The text and image plug-ins allow require.j
block will be run. What if we just want to run the main block while the program itself is being used, and not run the main block when it is entered by another module? This can be done through the __name__ property of the module. Using the __name__ of the module# !/usr/bin/python # Filename:using_name.py if __name__ ' __main__ ' : Print ' being run by itself ' Else : Print ' I am being imported from another module 'Results:
$
Module search order, duplicate import, module load list0x00 Module Search Order: Example:#test. Pyimport sysfor p in Sys.path:print (p) Run Result: Add content//pycharm to roots in C:\python pythonpathc:\python environment Script directory C:\Users\ihoney\AppData\Local\Programs\Python\Python35\python35.zip//package, Java bundle, avoid a large number of small file
Project on-line requirements have speech and nickname filtering requirements, the client is using Python script, Python script directly using the RE module for regular matching, the first practice is to open the game, each frame compiled 2 regular, but operational requirements inside 100+ a slightly more complex regular style, A compilation on the PC requires 80ms, causing the client to start the time lag.T
this time we use the concept of ' r\d ', and the regular is ' r\\d ' on it.Greedy matchGreedy match: Matches the string as long as possible when matching matches, by default, greedy matchSeveral commonly used non-greedy matching pattern*Repeat any number of times, but with as few repetitions as possible + repeat1 or more times, but with as few repetitions as possible? Repeat 0 or 1 times, but repeat {n,m} as little as possible. Repeat N to M, but repeat {n,} as little as possible, but repeat mo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.