Like a tree with many fruits, QWrap also has many apps"Extensions of JS native classes"Application, that is, apps/core_retouched.jshttp: // dev.qwrap.com/resource/js/#/core_retouched.js) application. This application extends native classes to facilitate user operations on native objects, such as String, Array, and Function.
Typical application scenarios of this application: jquery focuses on dom, so it lacks native object operations and module loading mechanisms. This library is exactly available and does not conflict with jquery.
As mentioned in previous articles, core/core_retouch.js is a retouch file.
The apps/core_retouched.js application described in this article is a composite file consisting of the following files:
- document.write('<script type="text/javascript" src="' + srcPath + 'core/core_base.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/module.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/browser.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/string.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/object.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/array.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/hashset.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/date.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/function.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/class.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/helper.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/custevent.h.js"><\/script>');
- document.write('<script type="text/javascript" src="' + srcPath + 'core/custevent_retouch.js"><\/script>');
-
- document.write('<script type="text/javascript" src="' + srcPath + 'core/core_retouch.js"><\/script>');
In practice, if you want to use on-demand asynchronous loading, you also need to add a module configuration file. For details, see QWrap getting started apps.
When a composite file is released and launched, it is merged into multiple files, and the file name remains unchanged. Merged content: apps/core_retouched.combo.js
Here is an example of the jquery + core_retouched application.
- <HTML> <HEAD> <TITLE> QWrap --- FunctionH. mul </TITLE>
- <META content = "text/html; charset = gb2312" http-equiv = Content-Type>
- <Script src = "http://common.cnblogs.com/script/jquery.js" type = "text/javascript"> </script>
- <Script src = "http://dev.qwrap.com/resource/js/apps/core_retouched.js" type = "text/javascript"> </script>
- </HEAD>
- <Body>
- <Div id = "id1"> what is the date? </Div>
- <Div id = "id2"> what is the time? </Div>
- <Input type = button value = "show" onclick = "test ()"/>
- </Body>
- <Script type = "text/javascript">
- Function test (){
- Values ('regionid1'hangzhou.html ('date is '+ new Date (). format ());
- Values ('regionid2'region.html ('date is '+ new Date (). format ('hh: mm: ss '));
- }
- </Script>
- </HTML>
In the above example, we need to use a date format, but this jquery does not provide, because jquery focuses on dom and does not provide the date format intent.
Some users have used prototype. js framework, like "new Date (). format () "," str. trim () "is a prototype usage. when I switched to jquery later, I felt that many methods were missing.
QWrap's core_retouched application is precisely "extended JS native class", specifically providing such applications.
Okay. Let's take a look at the convenience provided by core_retouched:
String-related
S. byteLen () // get the byte length
S. camelize () // hump
S. contains (subStr) // determines whether a string contains another string
S. dbc2sbc () // returns the fullwidth to halfwidth.
S. decamelize () // anti-hump
S. decode4Html () // transcode html
S. encode4Html () // decodes html
S. encode4HtmlValue () // transcode for htmlValue
S. encode4Http () // transcode http
S. encode4Js () // transcode js
S. evalExp (opts) // eval an expression
S. evalJs (opts) // eval statement
S. format (arg0) // string formatting // a Common Function
S. mulReplace (arr) // multiple update
S. stripTags () // remove tag content
S. subByte (len, tail) // truncate by byte length // This is useful when intercepting strings at the front end. This method is not provided by all foreign frameworks.
S. tmpl (opts) // string template is a very practical function. Later jquery also added.
S. trim () // remove spaces at both ends
Array-related:
Array. toArray (arr) // converts an ArrayLike object to an Array object.
Arr. clear () // clear an array
Arr. contains (obj) // determines whether the array contains an object.
Arr. every (callback, pThis) // scale according to the standard
Arr. expand () // expands a deep array Layer
Arr. filter (callback, pThis) // scale according to the standard
Arr. forEach (callback, pThis) // scale according to the standard // many libraries provide similar functions, and QWrap provides basic compatibility with the standard
Arr. indexOf (obj, fromIdx) // scale according to Standard
Arr. lastIndexOf (obj, fromIdx) // scale according to Standard
Arr. map (callback, pThis) // scale according to the standard
Arr. reduce (callback, initial) // scale according to Standard
Arr. reduceRight (callback, initial) // scale according to Standard
Arr. remove (obj) // remove an element from the array
Arr. some (callback, pThis) // scale according to the standard
Arr. unique () // array element deduplication
Arr. union (arr2) // returns the union of arrays.
Arr. intersect (arr2) // returns the intersection of arrays.
Date-related
D. format (pattern) // format the date
Function-related
Function. bind (func, thisObj) // scale according to the standard
Function. methodize (func, attr) // method of static functions
Function. mul (func, opt) // Let the first parameter of the method be an array
Function. createInstance (class) // scale according to the standard
Function. extend (class, p) // class inheritance // The class inheritance implemented by each library varies widely. This implementation is provided by shadow and curiosity.
Object-related
Object. isArray (obj) // determines whether the Object is an array.
Object. isArrayLike (obj) // determines whether the Object is ArrayLike.
Object. isElement (obj) // determines whether the Object is an html element.
Object. isFunction (obj )//...
Object. isObject (obj )//...
Object. isPlainObject (obj )//...
Object. isString (obj )//...
Object. dump (obj, props) // specify the output attribute
Object. fromArray (obj, keys, values) // expand the Object by keys and values
Object. get (obj, prop, nullSensitive) // strong get // in some cases, you can use ObjectH. get (obj, 'a. b. c. d ') to replace obj. a & obj. a. B & obj. a. b. c & obj. a. b. c. d
Object. keys (obj) // get keys
Object. map (obj, fn, thisObj) // refer to the map of array to implement the Object map.
Object. mix (des, src, override) // mixin
Object. set (obj, prop, value) // strong set
Object. stringify (obj) // serialize // stringify depends on JSON. stringify, but the second parameter is not supported.
Object. values () // obtain values
I have selected several special features and added links. It may take two minutes to take a look. ---- Every one of them is meaningful, limited in length, and cannot be described in detail. You can view them on your own.
For more information about the specific functions, see the link above.
In addition, for the help file corresponding to apps/core_retouched.js, see the content under the node "JS native object extension" in the left-side directory tree of the Help file.
The size of apps/core_retouched.js compressed by YUI is 17 K. It can be used independently and securely.
Appendix: QWrap blog: http://www.qwrap.com
Original article: http://www.cnblogs.com/jkisjk/archive/2011/04/21/qwrap_apps_core_retouched.html