CN104915212B - A kind of javascript module files for passing ginseng introduce the method performed - Google Patents

A kind of javascript module files for passing ginseng introduce the method performed Download PDF

Info

Publication number
CN104915212B
CN104915212B CN201510342432.5A CN201510342432A CN104915212B CN 104915212 B CN104915212 B CN 104915212B CN 201510342432 A CN201510342432 A CN 201510342432A CN 104915212 B CN104915212 B CN 104915212B
Authority
CN
China
Prior art keywords
parameter
script
label
code
module files
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510342432.5A
Other languages
Chinese (zh)
Other versions
CN104915212A (en
Inventor
陈健豪
艾建文
孙傲冰
季统凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
G Cloud Technology Co Ltd
Original Assignee
G Cloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by G Cloud Technology Co Ltd filed Critical G Cloud Technology Co Ltd
Priority to CN201510342432.5A priority Critical patent/CN104915212B/en
Publication of CN104915212A publication Critical patent/CN104915212A/en
Application granted granted Critical
Publication of CN104915212B publication Critical patent/CN104915212B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The present invention relates to front end development technique field, especially suitable introducing needs the flexible reusable javascript module files of incoming parameter.Present invention increase in the javascript module files being introduced into obtain it is incoming get parms, the interrelated logic code such as processing parameter, calling interface;Javascript module files are introduced by conventional,<script>According to the increase in demand custom parameter of module in label;The javascript module files being introduced into perform above-mentioned increased processing code during parsing is loaded, so as to realize independent introducing execution mechanism.The present invention can build a kind of javascript module files of quite flexible:<script>Parameter is passed at label can realize introducing execution mechanism;Traditional pattern can be used to carry out calling module interface for not incoming parameter.Introduce and perform for javascript modules.

Description

A kind of javascript module files for passing ginseng introduce the method performed
Technical field
The present invention relates to front end development technique field, especially suitable introducing needs incoming parameter flexibly reusable Javascript module files.
Background technology
The continuous development of front-end technology in recent years, the requirement more and more higher of man-machine interaction of the user to software interface so that The complexity of software interface also correspondingly becomes more and more higher, and front end developer is increasingly inclined to develop a kind of reusable Javascript modules are encapsulated in a single js file, wait introduce this module file when in use, using appropriate Parameter call interface can fast realize certain conventional interaction effect, reusable module development mode can greatly improve The operating efficiency of developer.
The prevalence that jquery frameworks and software are increased income simultaneously, the simple graceful smooth method of calling of jquery cause exploitation to become Into art, promote more and more people's exploitations are a kind of to call corresponding interface to realize complex effects by incoming suitable parameter Jquery plug-in units.
Traditional pattern is:Javascript module files are first introduced, code is write elsewhere and is passed to appropriate ginseng Number calling interface.This was a matter of course feelings originally, but as interaction of the user to interface is more and more, interface is introduced Javascript modules it is more and more, constantly repeat the pattern of introducing-calling.Code becomes increasingly complex, while code Degree of coupling constantly strengthens, and code becomes more and more bad and maintained.Some module some day needs to replace or deleted, and opens Hair personnel are needed to delete the introducing of javascript module files, and the code for calling this interface is then found in a pile code. If this is the situation for the code that other developer writes, current developer may be needed by multiple trial ability It is the code perfectness of calling interface correct to delete, be a pain for developer and also lose time but again The work that must be faced.
The content of the invention
Present invention solves the technical problem that it is that providing a kind of javascript module files for passing ginseng introduces what is performed Method, solves " introduce javascript module files -- calling javascript module interfaces elsewhere " this traditional mould The problem of code that formula is brought couples and is difficult in maintenance.
The present invention solve above-mentioned technical problem technical scheme be:
In the javascript module files being introduced into increase obtain it is incoming get parms, processing parameter, calling interface Deng interrelated logic code;Javascript module files are introduced by conventional,<script>According to the demand of module in label Increase custom parameter;The javascript module files being introduced into perform above-mentioned increased generation during parsing is loaded Code, so as to realize independent introducing execution mechanism.
The idiographic flow of methods described is:
The first step, addition acquisition is current on the basis of the javascript module files being introduced into<script>Label institute The logical code of incoming parameter;
Var scripts=document.getElementsByTagName (' script '),
// obtain all labels
Config=scripts [scripts.length-1] .getAttribute (' data-config ');
All parameters of // acquisition current label
This parameter of wherein data-config be to<script>Why the Custom Attributes that label is set, increase Data- prefix, it is because deferring to html5 standard, the attribute increase prefix to data type is easy to distinguish;If incoming ginseng Number is object type character strings, then increase is correctly parsed into object character strings the code of object types:
Config=eval (' ('+config+ ') ');
Second step, increase the logical code of processing parameter in javascript module files are introduced into:
(1).<script>Label is not passed to parameter:External code is waited to use parameter call interface;
(2).<script>It is default that label, which is passed to parameter and data-config parameters,:In inside modules according to definition Default parameters calling interface;
(3).<script>Label is passed to parameter and data-config parameters are non-default other values:In module The parameter call interface that portion is given tacit consent to using incoming parameters distribution;
3rd step, passes through<script>Label introduces javascript module files, and adds data-config=" {autoStart:1, second:1 } attribute ";
4th step, during parsing the javascript module files being introduced into, inside modules Code obtaining simultaneously parses Data-config parameter simultaneously covers the autoStart and second of acquiescence the two parameters;
5th step, the parameter call interface after merging is used in inside modules.
Do not passed in methods described parameter detailed introducing perform flow be:
The first step, add and obtain on the basis of the javascript module files being introduced into<script>Label is passed to The logical code of parameter:
Var scripts=document.getElementsByTagName (' script '),
Config=scripts [scripts.length-1] .getAttribute (' data-config ');
This parameter of wherein data-config be to<script>The attribute that label is set, the prefix for increasing data- is to abide by From html5 standard;
Second step, increase the judgement for not passing ginseng inside module file, when external code calling interface;
3rd step, use<script>Label normally introduces javascript module files;
4th step, parameter call interface is used in external code.
Of the invention the independence of javascript module files is strong compared with traditional pattern, without again in otherwise The interface for calling the javascript module files being introduced into be provided is completed to perform, it is only necessary to the incoming parameter when introducing Realize to introduce and perform.The present invention while compatible traditional pattern, are then held in the case of not incoming parameter using traditional pattern OK.
Brief description of the drawings
The present invention is further described below in conjunction with the accompanying drawings:
Fig. 1 is detailed process of the present invention.
Embodiment
As shown in figure 1, the present invention by<script>Be introduced into javascript set data-config parameters and Data-config detailed process is handled in the javascript module files being introduced into.
Below by the focus chart of one carousel of calling -- exemplified by jquery plug-in units easySlider, describe the present invention's in detail Embodiment:
The first step, code below is added in easySlider:
Get parms:
Second step, pass through<Script type=" text/javascript " data-sliderID=' #myslider ' Data-config=" { speed:600 } " src=" plugins/easyslider.js ">Mode introduce.Introduced with tradition The significant difference of mode is:It with the addition of the two parameters of data-sliderID and data-config.EasySlider modules text The code of first step addition is have invoked inside part during parsing, you can in the element that ID is myslider, use speed:600, auto:True, continuous:These three parameters of true perform easyslider effects.Wherein speed: 600 be to have used outside incoming mode, and other two has directly used the customized default value of inside modules, if desired for covering The two values are covered, in data-config increases.

Claims (2)

1. a kind of javascript module files for passing ginseng introduce the method performed, it is characterised in that:What is be introduced into In javascript module files increase obtain it is incoming get parms, the interrelated logic code of processing parameter, calling interface;Pass through It is conventional to introduce javascript module files,<script>According to the increase in demand custom parameter of module in label;Drawn The javascript module files entered perform above-mentioned increased code during parsing is loaded, so as to realize independent introducing Execution mechanism;
The idiographic flow of methods described is:
The first step, addition acquisition is current on the basis of the javascript module files being introduced into<script>Label is passed to Parameter logical code;
Utilize program var scripts=document.getElementsByTagName (' script '), the function of this code It is to obtain all script labels, scripts parameters represent to obtain all label objects;
Using program config=scripts [scripts.length-1] .getAttribute (' data-config '), this The function of code is to obtain all parameters of current label;
This parameter of wherein data-config be to<script>Why the Custom Attributes that label is set, increase data-'s Prefix, it is because deferring to html5 standard, the attribute increase prefix to data type is easy to distinguish;If incoming parameter is Object type character strings, then increase are correctly parsed into object character strings the code of object types;
Second step, increase the logical code of processing parameter in javascript module files are introduced into:
(1) if<script>Label is not passed to parameter:External code is waited to use parameter call interface;
(2) if<script>It is default that label, which is passed to parameter and data-config parameters,:In inside modules according to definition Default parameters calling interface;
(3) if<script>Label is passed to parameter and data-config parameters are non-default other values:In inside modules The parameter call interface given tacit consent to using incoming parameters distribution;
3rd step, passes through<script>Label introduces javascript module files, and adds data-config=" {autoStart:1,second:1 } attribute ";Wherein autoStart indicates whether to perform automatically, wherein, 0 represents not automatic Perform, 1, which represents automatic, performs;If autoStart is 0, the failure of second parameters;Otherwise second numerical value is bigger, The priority of execution is higher;
4th step, during parsing the javascript module files being introduced into, inside modules Code obtaining simultaneously parses data- Config parameter simultaneously covers the autoStart and second of acquiescence the two parameters;AutoStart is defaulted as 0, second ginsengs Number failure;
5th step, the parameter call interface after merging is used in inside modules.
2. according to the method for claim 1, it is characterised in that:The detailed introducing for not passing parameter in methods described performs flow For:
The first step, add and obtain on the basis of the javascript module files being introduced into<script>The incoming parameter of label institute Logical code;
In logical code, this parameter of data-config be to<script>The attribute that label is set, before increasing data- It is the standard for deferring to html5 to sew;
Second step, increase the judgement for not passing ginseng inside module file, when external code calling interface;If not incoming ginseng Number, does not make any processing;
3rd step, use<script>Label normally introduces javascript module files;
4th step, parameter call interface is used in external code.
CN201510342432.5A 2015-06-18 2015-06-18 A kind of javascript module files for passing ginseng introduce the method performed Active CN104915212B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510342432.5A CN104915212B (en) 2015-06-18 2015-06-18 A kind of javascript module files for passing ginseng introduce the method performed

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510342432.5A CN104915212B (en) 2015-06-18 2015-06-18 A kind of javascript module files for passing ginseng introduce the method performed

Publications (2)

Publication Number Publication Date
CN104915212A CN104915212A (en) 2015-09-16
CN104915212B true CN104915212B (en) 2018-03-30

Family

ID=54084296

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510342432.5A Active CN104915212B (en) 2015-06-18 2015-06-18 A kind of javascript module files for passing ginseng introduce the method performed

Country Status (1)

Country Link
CN (1) CN104915212B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106775788B (en) * 2015-11-19 2019-08-20 中国科学院声学研究所 A method of automatically generating and run JavaScript file
CN111061467B (en) * 2019-12-09 2023-03-21 东莞数汇大数据有限公司 Method for efficiently managing front-end engineering request module

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103440151A (en) * 2013-09-05 2013-12-11 北京京东尚科信息技术有限公司 Method and apparatus for dynamically loading Web page
CN103984548A (en) * 2014-05-14 2014-08-13 陕西上讯信息技术有限公司 Web application front end frame as well as construction method and system of Web application front frame
CN104331288A (en) * 2014-10-31 2015-02-04 北京思特奇信息技术股份有限公司 Method and system for showing dynamic page in configured manner
CN104375858A (en) * 2014-10-27 2015-02-25 深信服网络科技(深圳)有限公司 Method and device for multiple browser platforms to execute javascript

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB0016822D0 (en) * 2000-07-07 2000-08-30 Global Freight Exchange Limite Method computer system and computer system network for data management
US7689663B2 (en) * 2005-03-24 2010-03-30 Hewlett-Packard Development Company, L.P. Embedded web-based management method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103440151A (en) * 2013-09-05 2013-12-11 北京京东尚科信息技术有限公司 Method and apparatus for dynamically loading Web page
CN103984548A (en) * 2014-05-14 2014-08-13 陕西上讯信息技术有限公司 Web application front end frame as well as construction method and system of Web application front frame
CN104375858A (en) * 2014-10-27 2015-02-25 深信服网络科技(深圳)有限公司 Method and device for multiple browser platforms to execute javascript
CN104331288A (en) * 2014-10-31 2015-02-04 北京思特奇信息技术股份有限公司 Method and system for showing dynamic page in configured manner

Also Published As

Publication number Publication date
CN104915212A (en) 2015-09-16

Similar Documents

Publication Publication Date Title
CN110196719B (en) Business rule generation method and system based on natural language processing
CN102169500B (en) Dynamic service flow display method and device
CN103281311B (en) A kind of Internet of Things protocol analysis method using Protobuf to describe
CN103870260A (en) Method and system for service interface development
US9922009B2 (en) Network media information display system, method, apparatus and server
CN101968817B (en) Method for configuring webpage template
CN104915212B (en) A kind of javascript module files for passing ginseng introduce the method performed
CN102981855A (en) Template-based interface autogeneration method and system
CN106648662B (en) Report generation device and method based on project cost calculation description language BCL
WO2013029399A1 (en) Code generating method and system
CN104407863A (en) Abstract control model programming device and method
CN103677779A (en) Flexible page configuration showing method
CN110275700A (en) A kind of cross-platform multipad Development Framework and method based on electron
US20080155519A1 (en) Code translator
CN103019874A (en) Method and device for realizing exception handling based on data synchronization
CN104991952B (en) A kind of method of intelligent data distribution flow engine and its synchrodata
CN103246515A (en) Visual model view controller (MVC) function modeling control method
CN103984665A (en) Serial port communication device and method based on LabVIEW
CN110262783A (en) A kind of interface creation method, device and terminal device
CN103544298A (en) Log analysis method and analysis device for component
CN101324844B (en) Method for making rich text control with intelligent apperception
CN103116503A (en) Implement method and implement device of multiple windows
CN104918113B (en) A kind of the function card end compatibility method and system of module TV
CN104503733B (en) The merging method and device of a kind of state machine
CN105793842B (en) Conversion method and device between serialized message

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP02 Change in the address of a patent holder
CP02 Change in the address of a patent holder

Address after: 523808 19th Floor, Cloud Computing Center, Chinese Academy of Sciences, No. 1 Kehui Road, Songshan Lake Hi-tech Industrial Development Zone, Dongguan City, Guangdong Province

Patentee after: G-Cloud Technology Co., Ltd.

Address before: 523808 No. 14 Building, Songke Garden, Songshan Lake Science and Technology Industrial Park, Dongguan City, Guangdong Province

Patentee before: G-Cloud Technology Co., Ltd.