Skip to content

Commit

Permalink
~ 修正注释、API
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Jan 8, 2017
1 parent 137ef82 commit b8be1c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "blear.utils.object",
"version": "1.0.10",
"version": "1.0.11",
"description": "object utils",
"scripts": {
"live": "browser-sync start --config bs-config.js",
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Expand Up @@ -94,6 +94,12 @@ var define = exports.define = function (obj, key, desc) {
} else if (typeis.String(key)) {
desc = supply(desc, defineDefaults);

if (desc.get && !desc.set) {
desc.set = function () {
// empty
};
}

// 不能同时有 set 和 writable
if (desc.set && desc.writable) {
delete desc.writable;
Expand Down
19 changes: 16 additions & 3 deletions test/test.index.js
Expand Up @@ -94,8 +94,21 @@ describe('index.js', function () {
}
});

expect(o.b).toEqual(2);
expect(o.c).toEqual(null);
expect(o.b).toBe(2);
expect(o.c).toBe(null);
o.b = 3;
o.c = 4;
expect(o.b).toBe(3);
expect(o.c).toBe(4);

object.define(o, 'd', {
get: function () {
return 5;
}
});
expect(o.d).toBe(5);
o.d = 6;
expect(o.d).toBe(5);
});

it('.map', function (done) {
Expand Down Expand Up @@ -316,7 +329,7 @@ describe('index.js', function () {
expect(o3.b[1]).toBe(3);
});

it('.parsePath', function () {
it('.path', function () {
expect(object.path('a.b').join(' > ')).toEqual('a > b');
expect(object.path('a.b["c"]').join(' > ')).toEqual('a > b > c');
expect(object.path('a.b["c"].d').join(' > ')).toEqual('a > b > c > d');
Expand Down

0 comments on commit b8be1c4

Please sign in to comment.