Giter Club home page Giter Club logo

saber-lang's Introduction

saber-lang

Bower version NPM version Build Status License EFE Mobile Team

适合 移动端 & node 环境的 语言增强 模块。

Installation

浏览器环境下,通过 edp 引入模块:

$ edp import saber-lang

node 环境下,通过 npm 引入模块:

$ npm install saber-lang --save

Usage

var lang = require('saber-lang');

var targetObj = {x: 1, y: 2};
var sourceObj = {y: 3, z: 4};
lang.extend(targetObj, sourceObj);

console.log(targetObj); // {x: 1, y: 3, z: 4}

API

Base 部分是最基础的语言增强函数,在 require('saber-lang') 时加载。

Methods

extend(target, ...source)

对象属性拷贝。

  • target {Object} 目标对象
  • source {...Object} 源对象
  • return {Object}

inherits(subClass, superClass)

为类型构造器建立继承关系。

  • subClass {Function} 子类构造器
  • superClass {Function} 父类构造器
  • return {Function}

curry(fn[, ...args])

为函数提前绑定前置参数(柯里化)。

  • fn {Function} 要绑定的函数
  • args {...*=} 函数执行时附加到执行时函数前面的参数
  • return {Function}

bind(fn, thisArg[, ...args])

为函数绑定this与前置参数。

  • fn {Function} 要绑定的函数
  • thisArg {Object} 需要绑定的this
  • args {...*=} 函数执行时附加的前置绑定参数
  • return {Function}

Optional

浏览器环境下 还提供以下可选模块,使用时需要单独引用。

saber-lang's People

Contributors

firede avatar junmer avatar redmed avatar treelite avatar zfkun avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

wuhy cffirm

saber-lang's Issues

throttle实现逻辑有问题

function throttle(fn, wait, options) {
        options = options || {};

        var context;
        var args;
        var timer;
        var last = 0;

        var task = function () {
            last = options.leading === false ? 0 : Date.now();
            fn.apply(options.context || context, args);

            // 这里应该加上重置 timer = null;
        };

        return function () {
            context = this;
            args = arguments;

            var now = Date.now();

            if (!last && options.leading === false) {
                last = now;
            }

            var remaining = wait - (now - last);
            if (remaining <= 0 || remaining > wait) {
                timer = clearTimeout(timer);
                last = now;
                fn.apply(options.context || context, args);
            }
            else if (!timer && options.trailing !== false) {
                timer = setTimeout(task, remaining);
            }
        };
    }

增加 bind 函数

@treelite 看到你saber-viewport的更新,发现原来iOS 5.1.4之前不支持bind,估计你本地写好了,求更新 😆

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.