Open logan70 opened 4 years ago
jQuery源码
var jQuery = function(selector, context) { return new jQuery.fn.init(selector, context) } jQuery.fn = jQuery.prototype = { constructor: jQuery, ... // 各种原型方法 } jQuery.fn.init = function(selector, context, root) { ... } jQuery.fn.init.prototype = jQuery.fn // 校正实例的原型
Vue源码
function Vue(options) { this._init(options) } // initMixin Vue.prototype._init = function (options) { ... } // stateMixin Object.defineProperty(Vue.prototype, '$data', {...}) Object.defineProperty(Vue.prototype, '$props', {...}) Vue.prototype.$set = function() {...} Vue.prototype.$delete = function() {...} Vue.prototype.$watch = function() {...} // eventMixin Vue.prototype.$on = function() {...} Vue.prototype.$once = function() {...} Vue.prototype.$off = function() {...} Vue.prototype.$emit = function() {...} // lifecycleMixin Vue.prototype._update = function() {...} Vue.prototype.$forceUpdate = function() {...} Vue.prototype.$destory = function() {...} // renderMixin Vue.prototype.$nextTick = function() {...} Vue.prototype._render = function() {...}
开源项目中应用原型继承的案例
jQuery
jQuery源码
Vue
Vue源码