[removed] What are .extend and .prototype used for?

前端 未结 7 1012
渐次进展
渐次进展 2020-12-02 04:40

I am relatively new to JavaScript and keep seeing .extend and .prototype in third party libraries I am using. I thought it had to do with the Prototype javascript library, b

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 05:23

    Some extend functions in third party libraries are more complex than others. Knockout.js for instance contains a minimally simple one that doesn't have some of the checks that jQuery's does:

    function extend(target, source) {
        if (source) {
            for(var prop in source) {
                if(source.hasOwnProperty(prop)) {
                    target[prop] = source[prop];
                }
            }
        }
        return target;
    }
    

提交回复
热议问题