diff --git a/lib/scope.js b/lib/scope.js index 3094cc97..c1e6a51d 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -24,6 +24,17 @@ function defineScope(cls, targetClass, name, params, methods) { Object.defineProperty(cls, name, { enumerable: false, configurable: true, + /** + * This defines a property for the scope. For example, user.accounts or + * User.vips. Please note the cls can be the model class or prototype of + * the model class. + * + * The property value is function. It can be used to query the scope, + * such as user.accounts(condOrRefresh, cb) or User.vips(cb). The value + * can also have child properties for create/build/delete. For example, + * user.accounts.create(act, cb). + * + */ get: function () { var f = function caller(condOrRefresh, cb) { var actualCond = {}; @@ -84,7 +95,9 @@ function defineScope(cls, targetClass, name, params, methods) { // Wrap the property into a function for remoting var fn = function() { + // primaryObject.scopeName, such as user.accounts var f = this[name]; + // set receiver to be the scope property whose value is a function f.apply(this[name], arguments); };