Object.assign 重新绑定功能

问题描述

因为我需要声誉并且实际上无法对此线程发表评论Object.assign methods not binding 'this' 我打开我自己的问题:

这可以以某种方式解决或变通吗?我有一个包含

的“主”对象

NavigationLink

我正在将此主对象克隆到其他对象中,并且我希望 init 函数在从属对象的范围内运行,而不是在主对象的范围内运行。 有什么办法吗?

解决方法

实际上解决了我的问题:

https://gist.github.com/cowboy/5373000

如果 URL 失效,这里是附加代码:

Function.prototype.bind = (function(origBind) {
  return function() {
    var fn = origBind.apply(this,arguments);
    fn.__origFn__ = this.__origFn__ || this;
    return fn;
  };
}(Function.prototype.bind));

Function.prototype.unbind = function() {
  return this.__origFn__;
};