8000 GitHub - watchdb/observejs: 用于观察任意对象的任意变化的类库,以轻巧、实用、强大而闻名。
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

watchdb/observejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

##observe.js

用于观察任意对象的任意变化的类库,以轻巧、实用、强大而闻名。

##3分钟精通observe.js

对象字面量

var obj = { a: 1 };
//watch obj
observe(obj, function (name, value) {
    console.log(name + "__" + value);//a__2 
});
obj.a = 2;

数组

var arr = [1, 2, 3];
//watch obj
observe(arr, function (name, value, old) {
    console.log(name + "__" + value+"__"+old);
});
arr.push(4);//array__push_4 
arr[3] = 5;//3__5_4

复杂对象

var complexObj = { a: 1, b: 2, c: [{ d: [4] }] };
//watch complexObj
observe(complexObj, function (name, value) {
    console.log(name + "__" + value);    //d__100 
});
complexObj.c[0].d = 100;

普通对象

var User = function (name, age) {
    this.name = name;
    this.age = age;
    //只监听name
    observe(this,["name"] function (name, value, oldValue) {
        console.log(name + "__" + value + "__" + oldValue);//name__wangwu__lisi 
    });
}
var user = new User("lisi", 25);
user.name = "wangwu";

This content is released under the (http://opensource.org/licenses/MIT) MIT License.

About

用于观察任意对象的任意变化的类库,以轻巧、实用、强大而闻名。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 74.4%
  • HTML 25.6%
0