npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-fn-module

v0.1.0

Published

解决普通建站页面js代码混乱的问题,js执行代码越多会越乱。 > 像vue一样去写我们普通的前端代码,各种this的应用,便于页面功能模块的整理修改,以及相互调用,数据修改。

Downloads

3

Readme

js-fn-module

解决普通建站页面js代码混乱的问题,js执行代码越多会越乱。

像vue一样去写我们普通的前端代码,各种this的应用,便于页面功能模块的整理修改,以及相互调用,数据修改。

先来一段vue代码压压惊

下面代码可以看到this的妙用,this的调用很频繁,created会自动执行,methods之中定义的函数可以直接用this拿到data的数据,data可以直接调用插件的方法。

export default {
    data() {
        return {
            query: this.$route.query,//调用vue-router插件的方法
            loading: true,
            data: {
                list: []
            }
        }
    },
    created() {
        this.getData();
    },
    methods: {
        getData() {
            console.log(this.query)
        }
    },
    components: {}
}

普通js实现上面的方式去写代码

首先要解决this指向的问题,感兴趣的可以去看源代码,下面直接说明用法

var page = Page({
    data: function () {
        return {
            t: +new Date(),
            num:this.add(2,4)
        }
    },
    ready: function () {
        this.time('first');
        document.getElementById('third').innerHTML = this.num;
    },
    load: function () {
        this.time('second');
    },
    methods: {
        time: function (id) {
            var t = +new Date();
            document.getElementById(id).innerHTML = t - this.t + 'ms'
        }
    }
})

props

| name 名称 | type 类型 | default 默认值 | describe 描述 | | ------------ | :-----: | :---------: | ---------------------------------------- | | data | Function | | 静态参数,必须return一个obj,可以直接调用插件方法 | | ready | Function | | document.ready之后执行的方法 | | load | Function | |window.onload之后执行的方法 | | methods | Object | | 注册方法,方法之间可以互相调用 |

this默认方法

| name 名称 | type 类型 | default 默认值 | describe 描述 | | ------------ | :-----: | :---------: | ---------------------------------------- | | extend | Function | | 和jquery,angular的extend类似|

添加插件方法

再引入js-fn-module.js之后就可以注册插件。在页面调用之前引入,这样就可以愉快的使用插件了。

APP.prototype.add = function (a, b) {
    if (a && b) {
        return a + b;
    } else {
        return 0;
    }
}

书写插件项目启动方式

git clone 本项目之后可以启动项目,查看源代码,更去了解原理

  • clone 项目
    $ git clone https://github.com/codingdogs/js-fn-module.git
  • 下载npm依赖包
    $ npm i
  • 创建server,打开本地调试
    $ npm start