Giter Site home page Giter Site logo

perichr.js's Introduction

perichr.js

自用基础js库

基本用法

<script src="/js/perichr.js" data-PK="787BBFDC" data-options="{&quot;opt1&quot;:&quot;value1&quot;,&quot;opt2&quot;:&quot;value2&quot;}" data-init="demo1.js,demo2.js" ></script>

目前文件名必须是perichr.jsdata-PK是项目号,用于缓解不可控环境下引入多个perichr.js时造成的地址冲突。需要和模块中的key属性配套使用。在安全可控环境下,可以省略此选项(模块中也同步省略key属性)。 data-init是后续载入的脚本列表,逗号分隔。使用perichr.js所在目录的相对位置。无此选项则自动载入p.jsdata-options数据要求为标准JSON格式化文本串,当后续载入的脚本是以约定的方式编写的话可以调用到这些数据。

这里有个简单的模块示意:

P({  //这个是由perichr.js暴露的公开函数,用于模块的初始化。
    id: 'p.js',
    key: '787BBFDC',//项目号,缓解多perichr.js冲突
    Init: function(me){ //传入的me对象为主要操作对象,所有的可用特性都在这里。
        me.Load('p2.js', function(){ //
            console.log('p2.js已经载入,p.js准备做点啥了……')
            var p2 = me.GetPlugin('p2.js') 如果p2.js也是模块,则可以这样载入p2的me对象。
        })
	console.log(me.option.opt1)  //返回`undifined`。不能这样获取之前在`data-options`中定义的属性,此处option是为p.js单独设置的,目前还是空的。
	console.log(me.GetOption('opt1'))  //返回`value1`。用这个就可以了。会先查找`demo1.option`中的值,undifined时再检查`data-options`。
	console.log(me.option('opt1'))  //返回`value1`。这样也可以。
	me.option('opt1', 'val1')   //这样设置值。等同于`me.option.opt1 = val1`。
	console.log(me.option('opt1'))   //这时返回`val1`。
	
	me.GetFn('trim')('   1   ')       //调用perichr.js中公开的函数。
	me.fn('trim')('   1   ')       //这样也可以。
	me.fn.trim('   1   ')       //这样也可以。因为实际上已经把公开函数都复制了一遍到fn下。
	me.fn('trim', function(){})  //定义自己的函数。
	me.fn('trim', false)  //恢复默认的函数(如果有)。
    }
})

perichr.js's People

Contributors

perichr avatar

Stargazers

Austin Lee avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.