Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest参数&underscore创建对象方式 #6

Open
george-wq opened this issue Aug 11, 2019 · 0 comments
Open

rest参数&underscore创建对象方式 #6

george-wq opened this issue Aug 11, 2019 · 0 comments

Comments

@george-wq
Copy link
Owner

underscore rest参数 & underscore创建对象方式

underscore中 _.restArguments 用法:

var raceResults = _.restArguments(function(gold, silver, bronze, everyoneElse) {
  console.log(everyoneElse);
});

raceResults("Dopey", "Grumpy", "Happy", "Sneezy", "Bashful", "Sleepy", "Doc");

underscore创建对象方式

_.create

_.create 方法非常简单,根据你给的原型(prototype),以及一些 own properties,构造新的对象返回。

举个简单的例子:

var Person = function() {};

Person.prototype = {
  show: function() {
    alert(this.name);
  }
};

var me = _.create(Person.prototype, {name: 'hanzichi'});

console.log(me);

undercore 的实现思路也大抵如此。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant