js面向对象之继承学习 模拟策略模式
function CacheStrategy(){ this.getCache = function(CacheService){alert("cacheStrategy getCache function!");}; this.reloadCache = function(CacheService){alert("cacheStrategy reloadCache function!");}; } function MemCache(){ this.getCache = function(CacheService){ /** 缓存数据 **/ alert(CacheService.getData()); alert("memCache getCache function!"); }; this.reloadCache=function(CacheService){ alert("memCache reloadCache function!"); } } MemCache.prototype = new CacheStrategy(); function OsCache(){ this.getCache = function(CacheService){ /** 缓存数据 **/ alert(CacheService.getData()); alert("osCache getCache function!"); }; this.reloadCache=function(CacheService){ alert("OsCache reloadCache function!"); } } OsCache.prototype = new CacheStrategy(); function CacheService(){ this.getCache = function(CacheStrategy){}; this.getData = function(){alert("cacheService getData function !");}; this.getCacheKey = function(){}; this.useCache = function(){}; this.reloadCache = function(){}; } function AbstractCache(){ this.cacheKey = this.autoCacheKey(); this.useCache = true; this.cacheStrategy = new MemCache(); } AbstractCache.prototype = new CacheService(); AbstractCache.prototype.autoCacheKey = function(){ return "123"; } AbstractCache.prototype.setCacheKey = function(_cacheKey){ this.cacheKey = _cacheKey; } AbstractCache.prototype.getCacheKey = function(){ return this.cacheKey; } AbstractCache.prototype.setUseCache = function(_useCache){ this.useCache = _useCache; } AbstractCache.prototype.getUseCache = function(){ return this.useCache; } AbstractCache.prototype.setCacheStrategy = function(_cacheStrategy){ this.cacheStrategy = _cacheStrategy; } AbstractCache.prototype.getCache = function(){ return this.cacheStrategy.getCache(this); } AbstractCache.prototype.reloadCache = function(){ return this.cacheStrategy.reloadCache(this); } function ResourceCache(){ } ResourceCache.prototype = new AbstractCache(); ResourceCache.prototype.getData = function(){ return "data:11111111111111111111"; }
html测试页面
<html> <head> <script type="text/javascript" src="classtest.js" ></script> <title>js类测试</title> </head> <script> var abstractCache = new ResourceCache(); //abstractCache.setCacheStrategy(new OsCache()); abstractCache.getCache(); abstractCache.setCacheKey(456); alert(abstractCache.getCacheKey()); </script> <body> </body> </html>
相关推荐
JAVA面向对象基础测试题-继承-封装-多态等测试题.docx
猜拳游戏:java面向对象,kotlin面向对象,js面向对象,3个方法开发.zip.lnk猜拳游戏:java面向对象,kotlin面向对象,js面向对象,3个方法开发.zip.lnk猜拳游戏:java面向对象,kotlin面向对象,js面向对象,3个...
帮助理解js 面向对象,以及canvas 的使用
js面向对象之常见创建对象的几种方式(工厂模式、构造函数模式、原型模式).docx
Javascript面向对象与继承
函数、闭包、对象和原型等概念,以代码重用为目的的继承模式;BOM、DOM、浏览器事件、AJAX和JSON;如何实现JavaScript中缺失的面向对象特性,如对象的私有成员与私有方法;如何应用适当的编程模式,发挥JavaScript...
《JavaScript面向对象编程指南》内容包括:JavaScript作为一门浏览器语言的核心思想;面向对象编程的基础知识及其在JavaScript中的运用;数据类型、操作符以及流程控制语句;函数、闭包、对象和原型等概念,以代码...
函数、闭包、对象和原型等概念,以代码重用为目的的继承模式;BOM、DOM、浏览器事件、AJAX和JSON;如何实现JavaScript中缺失的面向对象特性,如对象的私有成员与私有方法;如何应用适当的编程模式,发挥JavaScript...
原型是理解继承概念的关键, 我们将会教你如何建立原型, 如何检测一个对象是否是另外一个对象的原型, 及其 JavaScript 的模型与Java 面向对象编程之间的区别。我们同样会向你展示如何检测对象所包含的各种属性的方法...
JS面向对象经典案例,JS面向对象过程中用到的一些技术,例如对象、类、JS继承Call、JS原型链Prototype、JS闭包等等
JavaScript面向对象继承详解,js进阶高手必读,内含六部分
NULL 博文链接:https://goyourauntie.iteye.com/blog/1179204
Javascript 面向对象的JavaScript进阶 Javascript技术
JS面向对象的基础 写的很好的,大家去看JS面向对象的基础 JS面向对象的基础 写的很好的,大家去看JS面向对象的基础
《JAVA面向对象程序设计》练习题---参考答案.doc
Java面向对象编程上机练习题.doc
本文件使用JavaScript已面向对象方式封装类来演示简单工厂模式的实现代码。以实例介绍了简单功能模式的用途,简单分析了实现的要件。mhtl文件里有实例代码的全部内容和分析简述。