a8m / a8m/obj-parse

Enhancement Suggestion for obj-parse setterFn

オープン
#1 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
3
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi Ariel, first off thank you for obj-parse and deepkeys. Both are wonderful utilities that I am using in my project(s). I wanted to send you this change to setterFn, as it might be of benefit to others who would like to be able to handle key values which are functions:

``` javascript
var setterFn = function(scope, path, value) {
var s = scope;
for(var i = 0; i < path.length - 1; i++) { //check the path
s = s[path[i]]; // s is the current path segment
if(angular.isUndefined(s)) { //make sure the path segment is good/defined
return undefined;
}
}
//ok, we have a good path, if it is a vanilla value return that, or, if a function call it
//probably we could be more sophisticated and do something like value.call(scope,path,value)
//just use value() for now
s[path[i]] = (angular.isFunction(value) ? value() : value);
return scope; //return the updated scope
};
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。